-
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.
Merge pull request #2671 from CAFECA-IO/feature/remain_mock
Feature/remain mock
- Loading branch information
Showing
15 changed files
with
581 additions
and
168 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
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,10 +1,9 @@ | ||
export interface ICompanySetting { | ||
id: number; | ||
companyId: number; | ||
autoRenewal: boolean; | ||
notifyTiming: number; | ||
notifyChannel: string; | ||
reminderFreq: number; | ||
createdAt: number; | ||
updatedAt: number; | ||
taxSerialNumber: string; | ||
representativeName: string; | ||
country: string; | ||
phone: string; | ||
address: string; | ||
} |
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,27 @@ | ||
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[]; | ||
} |
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,15 +1,22 @@ | ||
export interface IUserSetting { | ||
id: number; | ||
userId: number; | ||
personalInfo: IUserPersonalInfo; | ||
notificationSetting: INotificationSetting; | ||
createdAt: number; | ||
updatedAt: number; | ||
deletedAt: number; | ||
} | ||
interface INotificationSetting { | ||
systemNotification: boolean; | ||
updateAndSubscriptionNotification: boolean; | ||
emailNotification: boolean; | ||
} | ||
|
||
interface IUserPersonalInfo { | ||
firstName: string; | ||
lastName: string; | ||
country: string; | ||
phone: string; | ||
language: string; | ||
systemNotification: boolean; | ||
updateAndSubscriptionNotification: boolean; | ||
emailNotification: boolean; | ||
createdAt: number; | ||
updatedAt: number; | ||
deletedAt: number; | ||
phone: string; | ||
} |
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
96 changes: 96 additions & 0 deletions
96
src/pages/api/v2/company/[companyId]/company_setting/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,96 @@ | ||
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 { ICompanySetting } from '@/interfaces/company_setting'; | ||
|
||
// ToDo: (20240924 - Jacky) Implement the logic to get the company settings data from the database | ||
async function handleGetRequest() { | ||
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; | ||
let payload: ICompanySetting | 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 company settings data from the database | ||
// ToDo: (20240924 - Jacky) Format the company settings data to the ICompanySetting interface | ||
|
||
// Deprecated: (20240924 - Jacky) Mock data for connection | ||
payload = { | ||
id: 1, | ||
companyId: 1, | ||
taxSerialNumber: '123456789', | ||
representativeName: 'John Doe', | ||
country: 'USA', | ||
phone: '123-456-7890', | ||
address: '123 Main St, Anytown, USA', | ||
}; | ||
statusMessage = STATUS_MESSAGE.SUCCESS_LIST; | ||
|
||
return { statusMessage, payload }; | ||
} | ||
|
||
// ToDo: (20240924 - Jacky) Implement the logic to create a new company setting in the database | ||
async function handlePutRequest(req: NextApiRequest) { | ||
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; | ||
let payload: ICompanySetting | 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) Validate the request body | ||
// ToDo: (20240924 - Jacky) Implement the logic to create a new company setting in the database | ||
// ToDo: (20240924 - Jacky) Format the company settings data to the ICompanySetting interface | ||
|
||
// Deprecated: (20240924 - Jacky) Mock data for connection | ||
const newSetting: ICompanySetting = { | ||
id: 2, | ||
companyId: req.body.companyId, | ||
taxSerialNumber: req.body.taxSerialNumber, | ||
representativeName: req.body.representativeName, | ||
country: req.body.country, | ||
phone: req.body.phone, | ||
address: req.body.address, | ||
}; | ||
|
||
payload = newSetting; | ||
statusMessage = STATUS_MESSAGE.CREATED; | ||
|
||
return { statusMessage, payload }; | ||
} | ||
|
||
// Define method handlers for different HTTP methods | ||
const methodHandlers: { | ||
[key: string]: ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) => Promise<{ statusMessage: string; payload: ICompanySetting | null }>; | ||
} = { | ||
GET: handleGetRequest, | ||
PUT: handlePutRequest, | ||
}; | ||
|
||
// Main handler function to route requests to the appropriate handler | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<IResponseData<ICompanySetting | null>> | ||
) { | ||
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; | ||
let payload: ICompanySetting | null = null; | ||
|
||
try { | ||
// Determine the appropriate handler based on the HTTP method | ||
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 { | ||
// Format and send the response | ||
const { httpCode, result } = formatApiResponse<ICompanySetting | 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
Oops, something went wrong.