-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Update end time when event host ended room (#197)
* feat: update event end time * remove: draft query
- Loading branch information
1 parent
fd7eb7d
commit c4fbc45
Showing
3 changed files
with
92 additions
and
2 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,83 @@ | ||
import { getCurrentAuthenticated } from '@/(server)/_shared/utils/get-current-authenticated'; | ||
import { eventRepo, roomRepo } from '@/(server)/api/_index'; | ||
import { cookies } from 'next/headers'; | ||
import { NextResponse } from 'next/server'; | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
export async function POST({ params }: { params: { slugOrId: string } }) { | ||
const slugOrId = params.slugOrId; | ||
const cookieStore = cookies(); | ||
const requestToken = cookieStore.get('token'); | ||
|
||
try { | ||
if (!requestToken) { | ||
return NextResponse.json( | ||
{ | ||
code: 401, | ||
message: 'please check your authentication token', | ||
}, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
const response = await getCurrentAuthenticated(requestToken?.value); | ||
const user = response.data ? response.data : null; | ||
|
||
if (!user) { | ||
return NextResponse.json( | ||
{ | ||
code: 401, | ||
message: 'unauthorized', | ||
}, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
const room = await roomRepo.getRoomById(slugOrId); | ||
|
||
if (!room) { | ||
return NextResponse.json( | ||
{ | ||
code: 404, | ||
message: 'room not found', | ||
}, | ||
{ status: 404 } | ||
); | ||
} | ||
|
||
if (room?.meta.type === 'meeting') { | ||
const event = await eventRepo.getByRoomID(room.id); | ||
if (event) { | ||
event.endTime = new Date(); | ||
const newEvent = await eventRepo.updateEvent(user.id, event.id, event); | ||
|
||
return NextResponse.json( | ||
{ | ||
code: 200, | ||
message: 'event ended', | ||
data: newEvent, | ||
}, | ||
{ status: 200 } | ||
); | ||
} | ||
} | ||
|
||
return NextResponse.json( | ||
{ | ||
code: 200, | ||
message: 'normal room ended', | ||
data: room, | ||
}, | ||
{ status: 200 } | ||
); | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
return NextResponse.json( | ||
{ | ||
code: 500, | ||
message: 'internal server error', | ||
}, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
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