Skip to content

Commit 99e582b

Browse files
committed
add notification model
1 parent 983491e commit 99e582b

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

constants.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,22 @@ const PostTypes = {
3737
Testimonial: 'Testimonial'
3838
};
3939

40+
const NotificationStatus = {
41+
Read: 'Read',
42+
New: 'New'
43+
};
44+
45+
const NotificationType = {
46+
Post: 'Post',
47+
Nok: 'Nok'
48+
};
49+
4050
module.exports = {
4151
UserRoles,
4252
UserStatuses,
4353
Statuses,
54+
NotificationStatus,
55+
NotificationType,
4456
FlagStatuses,
4557
PostTypes
4658
};

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const War = require('./src/War')(sequelize, Sequelize);
4141
const NotificationPreference = require('./src/NotificationPreference')(sequelize, Sequelize);
4242
const Kin = require('./src/Kin')(sequelize, Sequelize);
4343
const Burial = require('./src/Burial')(sequelize, Sequelize);
44+
const Notification = require('./src/Notification')(sequelize, Sequelize);
4445

4546
// Create associations
4647
const belongsToMany = (source, target, through, as) => {
@@ -98,6 +99,7 @@ module.exports = {
9899
NotificationPreference,
99100
Kin,
100101
Burial,
102+
Notification,
101103
sequelize,
102104
Sequelize,
103105
syncDB: force => sequelize.sync({ force }),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const {NotificationStatus, NotificationType} = require('../constants');
4+
const _ = require('lodash');
5+
6+
module.exports = {
7+
up: (queryInterface, Sequelize) => {
8+
return queryInterface.createTable('Notifications', {
9+
id: {type: Sequelize.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true},
10+
content: {type: Sequelize.TEXT, allowNull: false},
11+
createdBy: {type: Sequelize.BIGINT, allowNull: false},
12+
status: {
13+
type: Sequelize.ENUM,
14+
allowNull: false,
15+
defaultValue: NotificationStatus.New,
16+
values: _.values(NotificationStatus),
17+
},
18+
userId: {type: Sequelize.BIGINT, allowNull: false},
19+
type: {
20+
type: Sequelize.ENUM,
21+
allowNull: false,
22+
values: _.values(NotificationType),
23+
},
24+
subType: {type: Sequelize.STRING},
25+
createdAt: {
26+
allowNull: false,
27+
type: Sequelize.DATE
28+
},
29+
updatedAt: {
30+
allowNull: false,
31+
type: Sequelize.DATE
32+
}
33+
});
34+
},
35+
down: (queryInterface, Sequelize) => {
36+
return queryInterface.dropTable('Notifications');
37+
}
38+
};

src/Notification.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const {NotificationStatus, NotificationType} = require('../constants');
4+
/*
5+
* Copyright (c) 2018 Topcoder, Inc. All rights reserved.
6+
*/
7+
8+
/*
9+
* the user notification definition
10+
*/
11+
module.exports = (sequelize, DataTypes) => sequelize.define('Notification', {
12+
id: {type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true},
13+
content: {type: DataTypes.TEXT, allowNull: false},
14+
createdBy: {type: DataTypes.BIGINT, allowNull: false}, // who trigger this notification
15+
status: {
16+
type: DataTypes.ENUM,
17+
allowNull: false,
18+
defaultValue: NotificationStatus.New,
19+
values: _.values(NotificationStatus),
20+
},
21+
userId: {type: DataTypes.BIGINT, allowNull: false}, // who will receive this notification
22+
type: {
23+
type: DataTypes.ENUM,
24+
allowNull: false,
25+
values: _.values(NotificationType),
26+
},
27+
subType: {type: DataTypes.STRING},
28+
});

0 commit comments

Comments
 (0)