-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(staging): officer verification (#2124)
* feat: run sendPasscodeCreationMessage conditionally * feat: add GovsgVerification model and migration * chore: add TODO * feat: implement storePrecreatedPasscode * refactor: set all fields in govsg_verification to be non-null on db-level * feat: create an empty GovsgMessages tab * feat: add table to GovsgMessages * feat: add GET /campaign/:campaignId/govsg/messages endpoint * feat: call govsg messages endpoint from frontend * feat: remove order * feat: handle button reply * fix: add missing diff * feat: allow only whitelisted users to conduct GovsgV * refactor: wrap <GovsgMessages> in function
- Loading branch information
Showing
20 changed files
with
811 additions
and
14 deletions.
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
43 changes: 43 additions & 0 deletions
43
backend/src/database/migrations/20230725081226-create-govsg-verification-table.js
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,43 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable('govsg_verification', { | ||
id: { | ||
type: Sequelize.DataTypes.BIGINT, | ||
allowNull: false, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
govsg_message_id: { | ||
type: Sequelize.DataTypes.BIGINT, | ||
allowNull: false, | ||
references: { | ||
model: 'govsg_messages', | ||
key: 'id', | ||
}, | ||
onUpdate: 'CASCADE', | ||
}, | ||
passcode_creation_wamid: { | ||
type: Sequelize.DataTypes.STRING(255), | ||
allowNull: false, | ||
}, | ||
passcode: { | ||
type: Sequelize.DataTypes.STRING(255), | ||
allowNull: false, | ||
}, | ||
created_at: { | ||
type: Sequelize.DataTypes.DATE, | ||
allowNull: false, | ||
}, | ||
updated_at: { | ||
type: Sequelize.DataTypes.DATE, | ||
allowNull: false, | ||
}, | ||
}) | ||
}, | ||
|
||
down: async (queryInterface, _) => { | ||
await queryInterface.dropTable('govsg_verification') | ||
}, | ||
} |
50 changes: 50 additions & 0 deletions
50
backend/src/govsg/middlewares/govsg-verification.middleware.ts
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,50 @@ | ||
import { Request, Response } from 'express' | ||
import { GovsgMessage } from '@govsg/models' | ||
import { GovsgVerification } from '@govsg/models/govsg-verification' | ||
|
||
export const listMessages = async ( | ||
req: Request, | ||
res: Response | ||
): Promise<Response | void> => { | ||
const { campaignId } = req.params | ||
const { offset, limit } = req.query | ||
const { rows, count } = await GovsgMessage.findAndCountAll({ | ||
where: { | ||
campaignId: +campaignId, | ||
}, | ||
offset: +(offset as string), | ||
limit: +(limit as string), | ||
include: [ | ||
{ | ||
model: GovsgVerification, | ||
attributes: ['passcode'], | ||
}, | ||
], | ||
}) | ||
const messages = rows.map((row) => { | ||
const { | ||
agency, | ||
recipient, | ||
officer_name, | ||
recipient_name, | ||
officer_designation, | ||
...remainingParams | ||
} = row.params as any | ||
console.debug( | ||
Check warning on line 33 in backend/src/govsg/middlewares/govsg-verification.middleware.ts
|
||
`Excluding agency=${agency} and officer_designation=${officer_designation} from params=${row.params}` | ||
) | ||
return { | ||
...row.get({ plain: true }), | ||
name: recipient_name, | ||
mobile: recipient, | ||
data: JSON.stringify(remainingParams), | ||
passcode: row.govsgVerification.passcode, | ||
sent: row.sendAttemptedAt, | ||
officer: officer_name, | ||
} | ||
}) | ||
return res.json({ | ||
messages, | ||
total_count: count, | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * as GovsgMiddleware from './govsg.middleware' | ||
export * as GovsgTemplateMiddleware from './govsg-template.middleware' | ||
export * as GovsgStatsMiddleware from './govsg-stats.middleware' | ||
export * as GovsgVerificationMiddleware from './govsg-verification.middleware' |
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,33 @@ | ||
import { | ||
BelongsTo, | ||
Column, | ||
DataType, | ||
ForeignKey, | ||
Model, | ||
Table, | ||
} from 'sequelize-typescript' | ||
import { GovsgMessage } from './govsg-message' | ||
|
||
@Table({ tableName: 'govsg_verification', underscored: true, timestamps: true }) | ||
export class GovsgVerification extends Model<GovsgVerification> { | ||
@Column({ | ||
type: DataType.BIGINT, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
allowNull: false, | ||
}) | ||
id: number | ||
|
||
@BelongsTo(() => GovsgMessage) | ||
govsgMessage: GovsgMessage | ||
|
||
@ForeignKey(() => GovsgMessage) | ||
@Column({ type: DataType.BIGINT, allowNull: false }) | ||
govsgMessageId: number | ||
|
||
@Column({ type: DataType.STRING, allowNull: false }) | ||
passcodeCreationWamid: string | ||
|
||
@Column({ type: DataType.STRING, allowNull: false }) | ||
passcode: string | ||
} |
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
Oops, something went wrong.