From db88621df1b85eb0ae73b61c251f2a941bb133e0 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Thu, 14 Nov 2024 17:09:42 +0700 Subject: [PATCH] feat: add get by id --- src/controllers/00-employment-office-controller.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/controllers/00-employment-office-controller.ts b/src/controllers/00-employment-office-controller.ts index 700cad9..d73b569 100644 --- a/src/controllers/00-employment-office-controller.ts +++ b/src/controllers/00-employment-office-controller.ts @@ -1,6 +1,7 @@ -import { Controller, Get, Query, Route, Tags } from "tsoa"; +import { Controller, Get, Path, Query, Route, Tags } from "tsoa"; import prisma from "../db"; import { queryOrNot } from "../utils/relation"; +import { notFoundError } from "../utils/error"; @Route("/api/v1/employment-office") @Tags("Employment Office") @@ -27,4 +28,15 @@ export class EmploymentOfficeController extends Controller { orderBy: [{ provinceId: "asc" }, { id: "asc" }], }); } + + @Get("{employmentOfficeId}") + async getEmploymentOffice(@Path() employmentOfficeId: string) { + const record = await prisma.employmentOffice.findFirst({ + where: { id: employmentOfficeId }, + }); + + if (!record) throw notFoundError("Employment Office"); + + return record; + } }