This repository has been archived by the owner on Aug 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
330 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ VIRGIL_APP_ID=sample | |
VIRGIL_APP_KEY_ID=sample | ||
VIRGIL_APP_KEY=sample | ||
|
||
JWT_SECRET=dooboolab | ||
JWT_SECRET=dooboolab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
const { | ||
STRING, | ||
TEXT, | ||
DATE, | ||
UUID, | ||
UUIDV4 | ||
} = require('sequelize'); | ||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable( | ||
'reactions', | ||
{ | ||
id: { | ||
type: UUID, | ||
defaultValue: UUIDV4, | ||
allowNull: false, | ||
primaryKey: true, | ||
}, | ||
type: { | ||
type: STRING, | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
type: DATE | ||
}, | ||
updatedAt: { | ||
type: DATE | ||
}, | ||
deletedAt: { | ||
type: DATE | ||
}, | ||
messageId: { | ||
type: UUID, | ||
references: { | ||
model: 'messages', | ||
key: 'id' | ||
}, | ||
allowNull: true, | ||
}, | ||
userId: { | ||
type: UUID, | ||
references: { | ||
model: 'users', | ||
key: 'id' | ||
}, | ||
allowNull: true | ||
}, | ||
}, | ||
{ | ||
charset: 'utf8mb4', | ||
} | ||
); | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('reactions'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
scalar DateTime | ||
|
||
type Reaction { | ||
id: ID! | ||
type: String | ||
createdAt: DateTime | ||
updatedAt: DateTime | ||
deletedAt: DateTime | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
BuildOptions, | ||
Model, | ||
STRING, | ||
TEXT, | ||
UUID, | ||
UUIDV4, | ||
} from 'sequelize'; | ||
|
||
import Message from './Message'; | ||
import User from './User'; | ||
import sequelize from '../db'; | ||
|
||
class Reaction extends Model { | ||
public id!: string; | ||
public type: string; | ||
public readonly createdAt!: Date; | ||
public readonly updatedAt!: Date; | ||
public readonly deletedAt!: Date; | ||
} | ||
|
||
Reaction.init({ | ||
id: { | ||
type: UUID, | ||
defaultValue: UUIDV4, | ||
allowNull: false, | ||
primaryKey: true, | ||
}, | ||
type: STRING, | ||
}, { | ||
sequelize, | ||
modelName: 'reaction', | ||
timestamps: true, | ||
paranoid: true, | ||
}); | ||
|
||
Reaction.belongsTo(Message, { as: 'message' }); | ||
Reaction.belongsTo(User, { as: 'user' }); | ||
|
||
export type ReactionModelStatic = typeof Model & { | ||
new (values?: object, options?: BuildOptions): Reaction; | ||
} | ||
|
||
export default Reaction as ReactionModelStatic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Reaction, Resolvers } from '../generated/graphql'; | ||
|
||
import { checkAuth } from '../utils/auth'; | ||
|
||
const resolver: Resolvers = { | ||
Mutation: { | ||
createReaction: async ( | ||
_, | ||
{ messageId, type }, | ||
{ verifyUser, models }, | ||
): Promise<Reaction> => { | ||
const auth = verifyUser(); | ||
checkAuth(auth); | ||
|
||
const { Reaction: reactionModel } = models; | ||
|
||
const reaction = await reactionModel.create({ | ||
messageId, | ||
userId: auth.userId, | ||
type, | ||
}); | ||
|
||
return reaction; | ||
}, | ||
deleteReaction: async ( | ||
_, | ||
{ reactionId }, | ||
{ verifyUser, models }, | ||
): Promise<number> => { | ||
const auth = verifyUser(); | ||
checkAuth(auth); | ||
|
||
const { Reaction: reactionModel } = models; | ||
|
||
const result = await reactionModel.destroy({ | ||
where: { | ||
id: reactionId, | ||
}, | ||
}); | ||
|
||
return result; | ||
}, | ||
}, | ||
}; | ||
|
||
export default resolver; |
Oops, something went wrong.