feat: implement complex user invitation handler with tests and configuration
This commit is contained in:
@@ -10,24 +10,38 @@ const complexParamsSchema = z.object({
|
||||
id: z.uuid(),
|
||||
});
|
||||
|
||||
export async function inviteComplexUserHandler(c: AppContext) {
|
||||
const user = c.get('user');
|
||||
const params = complexParamsSchema.parse(c.req.param());
|
||||
const payload = c.req.valid('json' as never) as InviteComplexUserInput;
|
||||
type InviteComplexUserHandlerDeps = {
|
||||
inviteComplexUser: typeof inviteComplexUser;
|
||||
ComplexMembersError: typeof ComplexMembersError;
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await inviteComplexUser(user.id, params.id, payload);
|
||||
return c.json(result, 201);
|
||||
} catch (error) {
|
||||
if (error instanceof ComplexMembersError) {
|
||||
return c.json(
|
||||
{ message: error.message },
|
||||
{
|
||||
status: error.status,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
export function createInviteComplexUserHandler(
|
||||
deps: InviteComplexUserHandlerDeps = {
|
||||
inviteComplexUser,
|
||||
ComplexMembersError,
|
||||
}
|
||||
) {
|
||||
return async function inviteComplexUserHandler(c: AppContext) {
|
||||
const user = c.get('user');
|
||||
const params = complexParamsSchema.parse(c.req.param());
|
||||
const payload = c.req.valid('json' as never) as InviteComplexUserInput;
|
||||
|
||||
try {
|
||||
const result = await deps.inviteComplexUser(user.id, params.id, payload);
|
||||
return c.json(result, 201);
|
||||
} catch (error) {
|
||||
if (error instanceof deps.ComplexMembersError) {
|
||||
return c.json(
|
||||
{ message: error.message },
|
||||
{
|
||||
status: error.status,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const inviteComplexUserHandler = createInviteComplexUserHandler();
|
||||
|
||||
Reference in New Issue
Block a user