typeorm#UpdateEvent TypeScript Examples
The following examples show how to use
typeorm#UpdateEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user-auth-forgotten-password.subscriber.ts From bank-server with MIT License | 6 votes |
async beforeUpdate({
entity,
}: UpdateEvent<UserAuthForgottenPasswordEntity>): Promise<void> {
if (entity.hashedToken) {
/**
* the hashedToken is longer than 72 characters, so it needs to be encoded first with sha256
*/
const hashedToken = UtilsService.encodeString(entity.hashedToken);
entity.hashedToken = await UtilsService.generateHash(hashedToken);
}
}
Example #2
Source File: question.subscriber.ts From office-hours with GNU General Public License v3.0 | 6 votes |
async afterUpdate(event: UpdateEvent<QuestionModel>): Promise<void> {
if (!event.entity) {
// TODO: this is kinda janky maybe fix
return;
}
await this.queueSSEService.updateQuestions(event.entity.queueId);
// Send push notification to students when they are hit 3rd in line
// if status updated to closed
if (
event.updatedColumns.find((c) => c.propertyName === 'status') &&
event.entity.status in ClosedQuestionStatus
) {
// get 3rd in queue before and after this update
const previousThird = await QuestionModel.waitingInQueue(
event.entity.queueId,
)
.offset(2)
.getOne();
const third = await QuestionModel.waitingInQueue(event.entity.queueId)
.setQueryRunner(event.queryRunner) // Run in same transaction as the update
.offset(2)
.getOne();
if (third && previousThird?.id !== third?.id) {
const { creatorId } = third;
this.notifService.notifyUser(creatorId, NotifMsgs.queue.THIRD_PLACE);
}
}
}
Example #3
Source File: user-auth.subscriber.ts From bank-server with MIT License | 5 votes |
beforeUpdate(event: UpdateEvent<UserAuthEntity>): void {
if (event.entity?.password !== event.databaseEntity?.password) {
event.entity.password = UtilsService.generateHash(event.entity.password);
}
}
Example #4
Source File: user.subscriber.ts From bank-server with MIT License | 5 votes |
beforeUpdate(event: UpdateEvent<UserEntity>): void {
if (event.entity?.lastName !== event.databaseEntity?.lastName) {
event.entity.lastName = UtilsService.capitalizeName(
event.entity.lastName,
);
}
}
Example #5
Source File: queue.subscriber.ts From office-hours with GNU General Public License v3.0 | 5 votes |
async afterUpdate(event: UpdateEvent<QueueModel>): Promise<void> {
if (event.entity) {
// Send all listening clients an update
await this.queueSSEService.updateQueue(event.entity.id);
}
}