-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor]: Optimize DeleteTimesheet and UpdateTimesheetStatus (#3375)
* Add createTimesheetFromApi function to create a timesheet entry from API * fix:update url * refactor: optimize deleteTimesheet and updateTimesheetStatus function for better readability * fix: deep scan * fix * fix: refactor some code * fix: deep scan * fix: Codacy Static Code Analysis * fix: build * feat: update billable from api * fix: conflits * fix: coderabbitai
- Loading branch information
1 parent
8a47843
commit 4eccf23
Showing
8 changed files
with
271 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { UpdateTimesheet } from "@/app/interfaces"; | ||
import { authenticatedGuard } from "@/app/services/server/guards/authenticated-guard-app"; | ||
import { updateTimesheetRequest } from "@/app/services/server/requests"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function PUT(req: Request) { | ||
const res = new NextResponse(); | ||
const { | ||
$res, | ||
user, | ||
tenantId, | ||
organizationId, | ||
access_token | ||
} = await authenticatedGuard(req, res); | ||
if (!user) return $res('Unauthorized'); | ||
|
||
try { | ||
const { searchParams } = new URL(req.url); | ||
const id = searchParams.get('id') as string; | ||
const body = (await req.json()) as UpdateTimesheet; | ||
const { data } = await updateTimesheetRequest( | ||
{ ...body, tenantId, organizationId, id }, | ||
access_token | ||
); | ||
return $res(data); | ||
} catch (error) { | ||
console.error('Error updating timesheet status:', error); | ||
return $res({ | ||
success: false, | ||
message: 'Failed to update timesheet status' | ||
}); | ||
} | ||
} |
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,31 @@ | ||
import { UpdateTimesheet } from "@/app/interfaces"; | ||
import { authenticatedGuard } from "@/app/services/server/guards/authenticated-guard-app"; | ||
import { createTimesheetRequest } from "@/app/services/server/requests"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function POST(req: Request) { | ||
const res = new NextResponse(); | ||
const { | ||
$res, | ||
user, | ||
tenantId, | ||
organizationId, | ||
access_token | ||
} = await authenticatedGuard(req, res); | ||
if (!user) return $res('Unauthorized'); | ||
|
||
try { | ||
const body = (await req.json()) as UpdateTimesheet; | ||
const { data } = await createTimesheetRequest( | ||
{ ...body, tenantId, organizationId }, | ||
access_token | ||
); | ||
return $res(data); | ||
} catch (error) { | ||
console.error('Error updating timesheet status:', error); | ||
return $res({ | ||
success: false, | ||
message: 'Failed to update timesheet status' | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.