-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurveyQuestionModel.js
More file actions
42 lines (35 loc) · 1.1 KB
/
surveyQuestionModel.js
File metadata and controls
42 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Model } from 'objection';
import { ModelNames } from '@utils/constants';
const path = require('path');
export class SurveyQuestionModel extends Model {
static get tableName() {
return ModelNames.MODEL_NAME__SURVEY_QUESTION;
}
async $beforeInsert() {
this.createdAt = new Date().toISOString();
this.updatedAt = new Date().toISOString();
}
async $beforeUpdate() {
this.updatedAt = new Date().toISOString();
}
static get relationMappings() {
return {
survey: {
relation: Model.BelongsToOneRelation,
modelClass: path.resolve(__dirname, './campaignSurveyModel.js'),
join: {
to: `${ModelNames.MODEL_NAME__CAMPAIGN_SURVEY}.id`,
from: `${ModelNames.MODEL_NAME__SURVEY_QUESTION}.campaignSurveyId`,
},
},
answers: {
relation: Model.HasManyRelation,
modelClass: path.resolve(__dirname, './surveyAnswerModel'),
join: {
from: `${ModelNames.MODEL_NAME__SURVEY_ANSWER}.surveyQuestionId`,
to: `${ModelNames.MODEL_NAME__SURVEY_QUESTION}.id`,
},
},
};
}
}