-
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
5 changed files
with
169 additions
and
15 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
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 |
---|---|---|
@@ -1,12 +1,27 @@ | ||
// export interface IPendingTask { | ||
// id: number; | ||
// userId: number; | ||
// taskType: string; | ||
// taskDescription: string; | ||
// taskTime: number; | ||
// taskStatus: string; | ||
// taskPriority: string; | ||
// createdAt: number; | ||
// updatedAt: number; | ||
// deletedAt: number; | ||
// } | ||
export interface IPendingTask { | ||
id: number; | ||
companyId: number; | ||
missingCertificate: IMissingCertificate; | ||
unpostedVoucher: IUnpostedVoucher; | ||
} | ||
|
||
interface IMissingCertificate { | ||
id: number; | ||
companyId: number; | ||
count: number; | ||
} | ||
|
||
interface IUnpostedVoucher { | ||
id: number; | ||
companyId: number; | ||
count: number; | ||
} | ||
|
||
export interface IPendingTaskTotal { | ||
id: number; | ||
userId: number; | ||
totalMissingCertificate: number; | ||
missingCertificateList: IMissingCertificate[]; | ||
totalUnpostedVoucher: number; | ||
unpostedVoucherList: IUnpostedVoucher[]; | ||
} |
68 changes: 68 additions & 0 deletions
68
src/pages/api/v2/company/[companyId]/pending_task/index.ts
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,68 @@ | ||
import { STATUS_MESSAGE } from '@/constants/status_code'; | ||
import { IResponseData } from '@/interfaces/response_data'; | ||
import { formatApiResponse } from '@/lib/utils/common'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { IPendingTask } from '@/interfaces/pending_task'; | ||
|
||
// ToDo: (20240924 - Jacky) Implement the logic to get the pending tasks data from the database | ||
async function handleGetRequest() { | ||
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; | ||
let payload: IPendingTask | null = null; | ||
|
||
// ToDo: (20240924 - Jacky) Get session data from the request | ||
// ToDo: (20240924 - Jacky) Check if the user is authorized to access this API | ||
// ToDo: (20240924 - Jacky) Implement the logic to get the pending tasks data from the database | ||
// ToDo: (20240924 - Jacky) Format the pending tasks data to the IPendingTaskTotal interface | ||
|
||
// Deprecated: (20240924 - Jacky) Mock data for connection | ||
payload = { | ||
id: 1, | ||
companyId: 1, | ||
missingCertificate: { | ||
id: 1, | ||
companyId: 1, | ||
count: 2, | ||
}, | ||
unpostedVoucher: { | ||
id: 1, | ||
companyId: 1, | ||
count: 3, | ||
}, | ||
}; | ||
statusMessage = STATUS_MESSAGE.SUCCESS_LIST; | ||
|
||
return { statusMessage, payload }; | ||
} | ||
|
||
const methodHandlers: { | ||
[key: string]: ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) => Promise<{ statusMessage: string; payload: IPendingTask | null }>; | ||
} = { | ||
GET: handleGetRequest, | ||
}; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<IResponseData<IPendingTask | null>> | ||
) { | ||
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; | ||
let payload: IPendingTask | null = null; | ||
|
||
try { | ||
const handleRequest = methodHandlers[req.method || '']; | ||
if (handleRequest) { | ||
({ statusMessage, payload } = await handleRequest(req, res)); | ||
} else { | ||
statusMessage = STATUS_MESSAGE.METHOD_NOT_ALLOWED; | ||
} | ||
} catch (_error) { | ||
const error = _error as Error; | ||
statusMessage = error.message; | ||
payload = null; | ||
} finally { | ||
const { httpCode, result } = formatApiResponse<IPendingTask | null>(statusMessage, payload); | ||
res.status(httpCode).json(result); | ||
} | ||
} |
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,71 @@ | ||
import { STATUS_MESSAGE } from '@/constants/status_code'; | ||
import { IResponseData } from '@/interfaces/response_data'; | ||
import { formatApiResponse } from '@/lib/utils/common'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import { IPendingTask, IPendingTaskTotal } from '@/interfaces/pending_task'; | ||
|
||
// ToDo: (20240924 - Jacky) Implement the logic to get the pending tasks data from the database | ||
async function handleGetRequest() { | ||
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; | ||
let payload: IPendingTaskTotal | null = null; | ||
|
||
// ToDo: (20240924 - Jacky) Get session data from the request | ||
// ToDo: (20240924 - Jacky) Check if the user is authorized to access this API | ||
// ToDo: (20240924 - Jacky) Implement the logic to get the pending tasks data from the database | ||
// ToDo: (20240924 - Jacky) Format the pending tasks data to the IPendingTaskTotal interface | ||
|
||
// Deprecated: (20240924 - Jacky) Mock data for connection | ||
payload = { | ||
id: 1, | ||
userId: 1, | ||
totalMissingCertificate: 5, | ||
missingCertificateList: [ | ||
{ id: 1, companyId: 1, count: 2 }, | ||
{ id: 2, companyId: 1, count: 3 }, | ||
], | ||
totalUnpostedVoucher: 3, | ||
unpostedVoucherList: [ | ||
{ id: 1, companyId: 1, count: 1 }, | ||
{ id: 2, companyId: 1, count: 2 }, | ||
], | ||
}; | ||
statusMessage = STATUS_MESSAGE.SUCCESS_LIST; | ||
|
||
return { statusMessage, payload }; | ||
} | ||
|
||
const methodHandlers: { | ||
[key: string]: ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) => Promise<{ statusMessage: string; payload: IPendingTask | IPendingTaskTotal | null }>; | ||
} = { | ||
GET: handleGetRequest, | ||
}; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<IResponseData<IPendingTask | IPendingTaskTotal | null>> | ||
) { | ||
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; | ||
let payload: IPendingTask | IPendingTaskTotal | null = null; | ||
|
||
try { | ||
const handleRequest = methodHandlers[req.method || '']; | ||
if (handleRequest) { | ||
({ statusMessage, payload } = await handleRequest(req, res)); | ||
} else { | ||
statusMessage = STATUS_MESSAGE.METHOD_NOT_ALLOWED; | ||
} | ||
} catch (_error) { | ||
const error = _error as Error; | ||
statusMessage = error.message; | ||
payload = null; | ||
} finally { | ||
const { httpCode, result } = formatApiResponse<IPendingTask | IPendingTaskTotal | null>( | ||
statusMessage, | ||
payload | ||
); | ||
res.status(httpCode).json(result); | ||
} | ||
} |