Spécification pour ma méthode d'instance de conférence:Sequelize: 'findAll' dans la méthode d'instance getParticipants()?
getParticipants(): Promise -> array des participants
modèle de la conférence:
return sequelize.define('conference', {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true
},
name: {
type: Sequelize.STRING,
allowNull: false,
unique: true
},
maxParticipants: {
type: Sequelize.INTEGER,
allowNull: false
},
fileShareSession: {
type: Sequelize.STRING,
defaultValue: null,
allowNull: true
},
startDate: {
type: Sequelize.DATE,
defaultValue: null,
allowNull: true
},
endDate: {
type: Sequelize.DATE,
defaultValue: null,
allowNull: true
},
state: {
type: Sequelize.ENUM(
ConferenceState.new,
ConferenceState.starting,
..
),
defaultValue: ConferenceState.new,
required: true,
allowNull: false
}
modèle Participant:
return sequelize.define('participant', {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true
},
displayName: {
type: Sequelize.STRING,
defaultValue: null,
allowNull: true
},
mediaResourceId: {
type: Sequelize.STRING,
defaultValue: null,
allowNull: true
},
screenSharingId: {
type: Sequelize.STRING,
defaultValue: null,
allowNull: true
},
mediaType: {
type: Sequelize.ENUM(
MediaType.AUDIO_VIDEO),
defaultValue: MediaType.AUDIO_VIDEO,
allowNull: false
},
state: {
type: Sequelize.ENUM(
ParticipantState.new,
ParticipantState.joining,
..
),
defaultValue: ParticipantState.new,
required: true,
allowNull: false
}
Question:
je peux donc faire une participant.findAll dans mon modèle d'instance de conférence ou non? Quand est-ce que je reçois un tableau avec un findAll?
je l'aurais fait comme ça:
// getParticipants() : Promise -> Participant array
getParticipants() {
return new Promise((resolve, reject) => {
var Participant = sequelize.models.participant;
Participant.findAll({
where: {
id: id
}
}).then(function(participant) {
if (_.isObject(participant)) {
resolve(participant);
} else {
throw new ResourceNotFound(conference.name, {id: id});
}
}).catch(function(err) {
reject(err);
});
});
},