Skip to content

Commit

Permalink
fix: add missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
loicguillois committed Jan 7, 2025
1 parent 2f204a8 commit 90a8f09
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions frontend/src/mocks/handlers/user-access-handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { constants } from 'http2';
import { http, HttpResponse, RequestHandler } from 'msw';

import {
SignupLinkDTO
} from '@zerologementvacant/models';
import data from './data';
import config from '../../utils/config';
import { isPast } from 'date-fns';

export const userAccessHandlers: RequestHandler[] = [
http.get<never, SignupLinkDTO>(
`${config.apiEndpoint}/api/user-access`,
({ request }) => {

const url = new URL(request.url);
const email = url.searchParams.get('email');
const signupLink = data.signupLinks.find((link) => link.prospectEmail === email);

if (!signupLink) {
return HttpResponse.json({
name: 'SignupLinkMissingError',
message: `Signup ${email} link missing`
},
{ status: constants.HTTP_STATUS_NOT_FOUND });
}

if (isPast(signupLink.expiresAt)) {
return HttpResponse.json({
name: 'SignupLinkExpiredError',
message: `Signup link expired`
},
{ status: constants.HTTP_STATUS_GONE });
}

const user = data.ceremaUsers.find((user) => user.email === email);
if(!user) {
return HttpResponse.json({
name: 'AuthenticationFailedError',
message: `Authentication failed.`
},
{ status: constants.HTTP_STATUS_UNAUTHORIZED });
}

if(user !== null) {
if(user.establishmentId === null) {
return HttpResponse.json({
name: 'EstablishmentMissingError',
message: `Establishment ${undefined} missing`
},
{ status: constants.HTTP_STATUS_NOT_FOUND });
}
return HttpResponse.json(user, {
status: constants.HTTP_STATUS_OK
});
}
}
)
];

0 comments on commit 90a8f09

Please sign in to comment.