Skip to content

Commit

Permalink
feat: auto rm blocked account after update
Browse files Browse the repository at this point in the history
  • Loading branch information
cooderl committed Mar 25, 2024
1 parent e74f6c6 commit fe10dba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/server/src/trpc/trpc.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class TrpcRouter {
update: data,
create: input,
});
this.trpcService.removeBlockedAccount(id);

return account;
}),
Expand All @@ -118,12 +119,15 @@ export class TrpcRouter {
where: { id },
data,
});
this.trpcService.removeBlockedAccount(id);
return account;
}),
delete: this.trpcService.protectedProcedure
.input(z.string())
.mutation(async ({ input: id }) => {
await this.prismaService.account.delete({ where: { id } });
this.trpcService.removeBlockedAccount(id);

return id;
}),
});
Expand Down
14 changes: 13 additions & 1 deletion apps/server/src/trpc/trpc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class TrpcService {
const blockedAccounts = blockedAccountsMap.get(today);

if (Array.isArray(blockedAccounts)) {
blockedAccounts.push(id);
if (id) {
blockedAccounts.push(id);
}
blockedAccountsMap.set(today, blockedAccounts);
} else {
blockedAccountsMap.set(today, [id]);
Expand All @@ -87,6 +89,16 @@ export class TrpcService {
);
}

removeBlockedAccount = (vid: string) => {
const today = this.getTodayDate();

const blockedAccounts = blockedAccountsMap.get(today);
if (Array.isArray(blockedAccounts)) {
const newBlockedAccounts = blockedAccounts.filter((id) => id !== vid);
blockedAccountsMap.set(today, newBlockedAccounts);
}
};

private getTodayDate() {
return dayjs.tz(new Date(), 'Asia/Shanghai').format('YYYY-MM-DD');
}
Expand Down

0 comments on commit fe10dba

Please sign in to comment.