-
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.
Implementing the server side API endpoints for managing friends
- Loading branch information
1 parent
a919d16
commit 4a02287
Showing
11 changed files
with
84 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { type RequestHandler, json, error } from '@sveltejs/kit'; | ||
import { pipe } from 'fp-ts/lib/function'; | ||
import { taskEither as TE } from 'fp-ts'; | ||
import { mapToApiError } from '$lib/server/mapApi'; | ||
import { acceptInvite } from '$lib/server/services/friendService'; | ||
|
||
export const POST: RequestHandler = async ({ locals, request }) => { | ||
const user = locals.user!; | ||
const body = await request.json(); | ||
|
||
return pipe( | ||
acceptInvite(body.inviteId, { id: user.id, email: user.email! }), | ||
TE.mapLeft(mapToApiError), | ||
TE.match( | ||
(err) => error(err.status, { message: err.message }), | ||
(connection) => json(connection) | ||
) | ||
)(); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { error, type RequestHandler } from '@sveltejs/kit'; | ||
import { pipe } from 'fp-ts/lib/function'; | ||
import { taskEither as TE } from 'fp-ts'; | ||
|
||
import { mapToApiError } from '$lib/server/mapApi'; | ||
import { removeConnection } from '$lib/server/services/friendService'; | ||
|
||
export const DELETE: RequestHandler = ({ locals, params }) => { | ||
if (!locals.user) { | ||
return error(401, { message: 'Unauthorized' }); | ||
} | ||
|
||
const friendId = params.id!; | ||
return pipe( | ||
removeConnection(locals.user!.id, friendId), | ||
TE.mapLeft(mapToApiError), | ||
TE.match( | ||
(err) => error(err.status, { message: err.message }), | ||
() => new Response(null, { status: 204 }) | ||
) | ||
)(); | ||
}; |
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,21 @@ | ||
import { error, type RequestHandler } from '@sveltejs/kit'; | ||
import { pipe } from 'fp-ts/lib/function'; | ||
import { taskEither as TE } from 'fp-ts'; | ||
import { mapToApiError } from '$lib/server/mapApi'; | ||
import { cancelInvite } from '$lib/server/services/friendService'; | ||
|
||
export const DELETE: RequestHandler = ({ locals, params }) => { | ||
if (!locals.user) { | ||
return error(401, { message: 'Unauthorized' }); | ||
} | ||
|
||
const inviteId = params.id!; | ||
return pipe( | ||
cancelInvite(inviteId), | ||
TE.mapLeft(mapToApiError), | ||
TE.match( | ||
(err) => error(err.status, { message: err.message }), | ||
() => new Response(null, { status: 204 }) | ||
) | ||
)(); | ||
}; |
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