Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r004 #50

Merged
merged 7 commits into from
Aug 27, 2024
Merged

r004 #50

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions src/app/api/v1/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ const generateErrorResponse = (e: any, status: number) => {
// export const dynamic = 'force-static';

export async function POST(request: CombineRequest) {
const isHealthCheck = request?.headers?.get('x-dp-keepalive') === process.env.NEXUS_KEEPALIVE;
const healthSecret =
request?.headers?.get('x-dp-keepalive') ||
request?.cookies?.toString()?.split('dp-health-check=')[1].split(';')[0] ||
request?.headers?.get('cookies')?.toString()?.split('dp-health-check=')[1].split(';')[0] ||
'';
const isHealthCheck = healthSecret === process.env.NEXUS_KEEPALIVE;

if (isHealthCheck) {
try {
await GetPrivateCommonAbilities({});
Expand All @@ -40,41 +46,39 @@ export async function POST(request: CombineRequest) {
}
}

const cookies = request?.cookies?.toString() || request?.headers?.get('cookies');
const session = await GetSession({ cookies: cookies || '' });
const user = session?.user;
try {
const cookies = request?.cookies?.toString() || request?.headers?.get('cookies');
const session = await GetSession({ cookies: cookies || '' });
const user = session?.user;

const body = await request?.json();
const action = body?.action;
// const listings = body?.action;
const body = await request?.json();
const action = body?.action;

if (!!user && !!action) {
const payload = { data: {} };
try {
if (!!user && !!action) {
const payload = { data: {} };
if (action === 'get-own-abilities') {
payload.data = await GetPrivateAbilities({ filters: ['user'], user });
} else if (action === 'get-own-services') {
payload.data = await GetPrivateServices({ filters: ['user'], user });
} else {
throw new Error('Code 000/1: No specified action');
}
} catch (e) {
return NextResponse.json(generateErrorResponse(e, 400), { status: 400 });
return NextResponse.json(
{
ok: true,
status: 200,
data: payload.data,
},
{
status: 200,
},
);
}

return NextResponse.json(
{
ok: true,
status: 200,
data: payload.data,
},
{
status: 200,
},
);
return NextResponse.json(generateErrorResponse({ message: 'Code 000: Malformed request' }, 400), { status: 400 });
} catch (e) {
return NextResponse.json(generateErrorResponse(e, 400), { status: 400 });
}

return NextResponse.json(generateErrorResponse({ message: 'Code 000: Malformed request' }, 400), { status: 400 });
}

export async function PATCH(request: CombineRequest) {
Expand Down
Loading