Skip to content

Commit

Permalink
feat: modify url path and http method
Browse files Browse the repository at this point in the history
  • Loading branch information
RexBearIU committed Sep 26, 2024
1 parent 8ddd6a6 commit 5a5fb50
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 261 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iSunFA",
"version": "0.8.2+15",
"version": "0.8.2+16",
"private": false,
"scripts": {
"dev": "next dev",
Expand Down

This file was deleted.

31 changes: 17 additions & 14 deletions src/pages/api/v2/company/[companyId]/accounting_setting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,33 @@ async function handleGetRequest() {
return { statusMessage, payload };
}

// ToDo: (20240924 - Jacky) Implement the logic to create a new accounting setting in the database
async function handlePostRequest(req: NextApiRequest) {
// ToDo: (20240924 - Jacky) Implement the logic to update an existing accounting setting in the database
async function handlePutRequest(req: NextApiRequest) {
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST;
let payload: IAccountingSetting | 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 accounting setting in the database
// ToDo: (20240924 - Jacky) Implement the logic to update an existing accounting setting in the database
// ToDo: (20240924 - Jacky) Format the accounting settings data to the IAccountingSetting interface

// Deprecated: (20240924 - Jacky) Mock data for connection
const newSetting: IAccountingSetting = {
id: 1,
companyId: 2,
companyName: req.body.companyName,
taxSettings: req.body.taxSettings,
currency: req.body.currency,
lastDayOfFiscalYear: req.body.lastDayOfFiscalYear,
shortcutList: req.body.shortcutList,
const { companyId, companyName, taxSettings, currency, lastDayOfFiscalYear, shortcutList } =
req.body;

const updatedAccountingSetting: IAccountingSetting = {
id: 123,
companyId,
companyName,
taxSettings,
currency,
lastDayOfFiscalYear,
shortcutList,
};

payload = newSetting;
statusMessage = STATUS_MESSAGE.CREATED;
payload = updatedAccountingSetting;
statusMessage = STATUS_MESSAGE.SUCCESS_UPDATE;

return { statusMessage, payload };
}
Expand All @@ -77,7 +80,7 @@ const methodHandlers: {
) => Promise<{ statusMessage: string; payload: IAccountingSetting | null }>;
} = {
GET: handleGetRequest,
POST: handlePostRequest,
PUT: handlePutRequest,
};

export default async function handler(
Expand Down

This file was deleted.

This file was deleted.

25 changes: 14 additions & 11 deletions src/pages/api/v2/user/[userId]/user_setting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ async function handleGetRequest() {
return { statusMessage, payload };
}

// ToDo: (20240924 - Jacky) Implement the logic to create a new user setting in the database
async function handlePostRequest(req: NextApiRequest) {
// ToDo: (20240924 - Jacky) Implement the logic to update an existing user setting in the database
async function handlePutRequest(req: NextApiRequest) {
let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST;
let payload: IUserSetting | 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 user setting in the database
// ToDo: (20240924 - Jacky) Implement the logic to update an existing user setting in the database
// ToDo: (20240924 - Jacky) Format the user settings data to the IUserSetting interface

// Deprecated: (20240924 - Jacky) Mock data for connection
const {
userId,
firstName,
lastName,
country,
Expand All @@ -60,13 +61,15 @@ async function handlePostRequest(req: NextApiRequest) {
systemNotification,
updateAndSubscriptionNotification,
emailNotification,
createdAt,
deletedAt,
} = req.body;

const now = Date.now();
const nowTimestamp = timestampInSeconds(now);
const newIUserSetting: IUserSetting = {
id: 3,
userId: req.body.userId, // ToDo: (20240926 - Jacky) Get the user ID from the session
const updatedIUserSetting: IUserSetting = {
id: 1,
userId,
personalInfo: {
firstName,
lastName,
Expand All @@ -79,13 +82,13 @@ async function handlePostRequest(req: NextApiRequest) {
updateAndSubscriptionNotification,
emailNotification,
},
createdAt: nowTimestamp,
createdAt,
updatedAt: nowTimestamp,
deletedAt: 0,
deletedAt,
};

payload = newIUserSetting;
statusMessage = STATUS_MESSAGE.CREATED;
payload = updatedIUserSetting;
statusMessage = STATUS_MESSAGE.SUCCESS_UPDATE;

return { statusMessage, payload };
}
Expand All @@ -97,7 +100,7 @@ const methodHandlers: {
) => Promise<{ statusMessage: string; payload: IUserSetting | null }>;
} = {
GET: handleGetRequest,
POST: handlePostRequest,
PUT: handlePutRequest,
};

export default async function handler(
Expand Down

0 comments on commit 5a5fb50

Please sign in to comment.