-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
108 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
15 changes: 15 additions & 0 deletions
15
apps/web-api/prisma/migrations/20241219130952_add_telegram_uid_unique/migration.sql
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,15 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[telegramHandler]` on the table `Member` will be added. If there are existing duplicate values, this will fail. | ||
- A unique constraint covering the columns `[telegramUid]` on the table `Member` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Member" ADD COLUMN "telegramUid" TEXT; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Member_telegramHandler_key" ON "Member"("telegramHandler"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Member_telegramUid_key" ON "Member"("telegramUid"); |
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,35 @@ | ||
import { Controller, UseGuards, Body, BadRequestException, NotFoundException } from '@nestjs/common'; | ||
import { Api, initNestServer, ApiDecorator } from '@ts-rest/nest'; | ||
import { apiInternals } from 'libs/contracts/src/lib/contract-internals'; | ||
import { InternalUpdateMemberDto, ResponseMemberSchema } from 'libs/contracts/src/schema'; | ||
import { ApiOkResponseFromZod } from '../decorators/api-response-from-zod'; | ||
import { InternalAuthGuard } from '../guards/auth.guard'; | ||
import { MembersService } from '../members/members.service'; | ||
|
||
const server = initNestServer(apiInternals); | ||
type RouteShape = typeof server.routeShapes; | ||
|
||
@Controller("") | ||
@UseGuards(InternalAuthGuard) | ||
export class MembersController { | ||
constructor( | ||
private readonly membersService: MembersService | ||
) {} | ||
|
||
@Api(server.route.updateTelagramUid) | ||
@ApiOkResponseFromZod(ResponseMemberSchema) | ||
async updateTelegramUid( | ||
@Body() updateRequestDto: InternalUpdateMemberDto | ||
) { | ||
if(updateRequestDto.telegramHandler) { | ||
const member = await this.membersService.findUnique({telegramHandler: {equals: updateRequestDto.telegramHandler, mode: 'insensitive'}}); | ||
if(member) { | ||
return await this.membersService.updateMemberByUid(member.uid, {telegramUid: updateRequestDto.telegramUid}); | ||
} | ||
throw new NotFoundException(`Member with telegram handle ${updateRequestDto.telegramHandler} not found`); | ||
|
||
} else { | ||
throw new BadRequestException('Telegram handle cannot be empty'); | ||
} | ||
} | ||
} |
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
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
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