0

Ahora estoy de lleno en una aplicación NodeJS, y tengo el siguiente problema. Estoy desarrollando el siguiente modelo, Suggestion:

'use strict';

/**
 * User model
 * @module models/Suggestion
 */

import { Model, model,Schema, ObjectId } from 'mongoose';
import db = require('../lib/utils/db');
const dbUtils = require("../lib/utils/db");


/*  Model Interfaces    */


export interface ISuggestion extends IAddSuggestion{
    userId : String;
    subject : String;
    message: String;
    sendDate : Date;


};

export interface IAddSuggestion{
    subject : String;
    message: String;
};

export interface ISuggestionMongoModel extends ISuggestion, Model<ISuggestion>{

  _id: ObjectId;
  addSuggestion(newSuggestion: ISuggestion): Promise<ISuggestionMongoModel>;

};



/*  DB Model    */
const schema = new Schema<ISuggestionMongoModel>({
    userId : String,
    subject : String,
    message: String,
    sendDate : Date,

  });


  //let Suggestion = model<ISuggestionMongoModel>('Suggestion', schema);

  /**
 * Add new Suggestion
 * @method new
 * @param {ISuggestion} newSuggestion The record to insert in the database
 * @return {Promise<ISuggestion>}
 */
schema.statics.addSuggestion = function (newSuggestion: ISuggestion): Promise<ISuggestionMongoModel> {
  try {
    let row = dbUtils.insertRow(Suggestion, newSuggestion);
    return row;
  } catch (err) {
    return Promise.reject(err);
  }
};


const Suggestion: ISuggestionMongoModel = model<ISuggestion, ISuggestionMongoModel>("Suggestion", schema);


  export {Suggestion};

Y no puedo utilizar los atributos o métodos en otros archivos, ya que me aparece el siguiente error:

Al tipo "Model<ISuggestion, {}, {}, {}>" le faltan las propiedades siguientes del tipo "ISuggestionMongoModel": _id, addSuggestion, userId, subject y 2 más.ts(2740) const Suggestion: ISuggestionMongoModel

¿Por qué me aparece este error?

1 respuesta 1

0

Pues la respuesta era sencilla. Se trataba solamente de eliminar el tipo de schema:

/*  DB Model    */
const schema = new Schema({
    userId : String,
    subject : String,
    message: String,
    sendDate : Date,

  });

En lugar de:

/*  DB Model    */
const schema = new Schema<ISuggestionMongoModel>({
    userId : String,
    subject : String,
    message: String,
    sendDate : Date,

  });

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.