Created
November 18, 2025 21:31
-
-
Save alexmkio/a049cad75cd6933b22c45da932859b75 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { NextApiRequest, NextApiResponse } from 'next'; | |
| import { AddClientNoteRequestModel } from '@generated/api/models/AddClientNoteRequestModel'; | |
| import { ClientNoteSortOption } from '@generated/api/models/ClientNoteSortOption'; | |
| import { SortDirection } from '@generated/api/models/SortDirection'; | |
| import { appClient } from '@lib/api/appClient'; | |
| import { withMethodRestriction } from '@lib/api/utils/withMethodRestriction'; | |
| import { HTTP_METHODS } from '@lib/constants'; | |
| async function handler(req: NextApiRequest, res: NextApiResponse) { | |
| const { clientId, sortOption, sortDirection, pageSize, pageIndex } = | |
| req.query; | |
| const api = await appClient(req); | |
| if (req.method === 'GET') { | |
| return api.clients | |
| .getClientsNotes( | |
| clientId as string, | |
| sortOption | |
| ? (sortOption as ClientNoteSortOption) | |
| : ClientNoteSortOption.CREATEDDATE, | |
| sortDirection | |
| ? (sortDirection as SortDirection) | |
| : SortDirection.ASCENDING, | |
| pageSize ? parseInt(pageSize as string) : 1000, | |
| pageIndex ? parseInt(pageIndex as string) : 1, | |
| ) | |
| .then((data) => res.status(200).json(data)) | |
| .catch((error) => res.status(error.status).json(error)); | |
| } else if (req.method === 'POST' || req.method === 'PATCH') { | |
| return api.clients | |
| .postClientsNotes( | |
| clientId as string, | |
| req.body as AddClientNoteRequestModel, | |
| ) | |
| .then((data) => res.status(200).json(data)) | |
| .catch((error) => res.status(error.status).json(error)); | |
| } | |
| } | |
| export default withMethodRestriction(handler, [ | |
| HTTP_METHODS.GET, | |
| HTTP_METHODS.POST, | |
| ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment