Skip to content

Commit

Permalink
update backend (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincetiu8 authored Nov 10, 2024
1 parent c0e8276 commit d98fa35
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 291 deletions.
126 changes: 56 additions & 70 deletions server/src/controllers/birthdayRequest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {
emailRequestUpdate,
emailRequestDelete,
} from '../services/mail.service.ts';
import { IBirthdayRequest } from '../models/birthdayRequest.model.ts';
import {
ChildGender,
ChildRace,
ChildSituation,
IBirthdayRequest,
} from '../models/birthdayRequest.model.ts';
import { IChapter } from '../models/chapter.model.ts';

const getAllRequests = async (
Expand Down Expand Up @@ -167,26 +172,31 @@ const createRequest = async (
chapterId,
deadlineDate,
childBirthday,
childAge,
childName,
childGender,
childRace,
childAge,
childGenderRaw,
childRaceRaw,
childInterests,
giftSuggestions,
childAllergies,
allergyDetails,
giftSuggestions,
additionalInfo,
childSituationRaw,
agencyWorkerName,
agencyOrganization,
agencyWorkerPhone,
agencyWorkerEmail,
agencyPhysicalAddress,
isFirstReferral,
agreeFeedback,
requestedDate,
status,
deliveryDate,
agreeLiability,
} = req.body;
if (!chapterId || typeof chapterId === 'string') {

const childGender = childGenderRaw as ChildGender;
const childRace = childRaceRaw as ChildRace;
const childSituation = childSituationRaw as ChildSituation;

if (!chapterId || typeof chapterId !== 'string') {
next(ApiError.notFound(`chapterId does not exist or is invalid`));
return;
}
Expand All @@ -198,70 +208,57 @@ const createRequest = async (
next(ApiError.notFound(`childBirthday does not exist or is invalid`));
return;
}
if (!childAge || typeof childAge !== 'number') {
next(ApiError.notFound(`childAge does not exist or is invalid`));
return;
}
if (!childName || typeof childName === 'string') {
if (!childName || typeof childName !== 'string') {
next(ApiError.notFound(`childName does not exist or is invalid`));
return;
}
if (!childGender || typeof childGender === 'string') {
next(ApiError.notFound(`childGender does not exist or is invalid`));
return;
}
if (childGender !== 'Boy' && childGender !== 'Girl') {
next(ApiError.notFound(`childGender is invalid`));
return;
}
if (!childRace || typeof childRace === 'string') {
next(ApiError.notFound(`childRace does not exist or is invalid`));
if (!childAge || typeof childAge !== 'number') {
next(ApiError.notFound(`childAge does not exist or is invalid`));
return;
}
if (
childRace !== 'White' &&
childRace !== 'Black or African American' &&
childRace !== 'Hispanic or Latino' &&
childRace !== 'Native American or American Indian' &&
childRace !== 'Asian / Pacific Islander' &&
childRace !== 'Not Sure'
) {
next(ApiError.notFound(`childRace is invalid`));

if (!childInterests || typeof childInterests !== 'string') {
next(ApiError.notFound(`childInterests does not exist or is invalid`));
return;
}
if (!childInterests || typeof childInterests === 'string') {
next(ApiError.notFound(`childInterests does not exist or is invalid`));
if (!giftSuggestions || typeof giftSuggestions !== 'string') {
next(ApiError.notFound(`giftSuggestions does not exist or is invalid`));
return;
}
if (childAllergies !== true && childAllergies !== false) {
if (typeof childAllergies !== 'boolean') {
next(ApiError.notFound(`childAllergies does not exist or is invalid`));
return;
}
if (!allergyDetails || typeof allergyDetails === 'string') {
if (!allergyDetails || typeof allergyDetails !== 'string') {
next(ApiError.notFound(`allergyDetails does not exist or is invalid`));
return;
}
if (!giftSuggestions || typeof giftSuggestions === 'string') {
next(ApiError.notFound(`giftSuggestions does not exist or is invalid`));
return;
}
if (!additionalInfo || typeof additionalInfo === 'string') {
if (!additionalInfo || typeof additionalInfo !== 'string') {
next(ApiError.notFound(`additionalInfo does not exist or is invalid`));
return;
}
if (!agencyWorkerName || typeof agencyWorkerName === 'string') {

if (!agencyWorkerName || typeof agencyWorkerName !== 'string') {
next(ApiError.notFound(`agencyWorkerName does not exist or is invalid`));
return;
}
if (!agencyOrganization || typeof agencyOrganization === 'string') {
if (!agencyOrganization || typeof agencyOrganization !== 'string') {
next(ApiError.notFound(`agencyOrganization does not exist or is invalid`));
return;
}
if (!agencyWorkerPhone || typeof agencyWorkerPhone === 'string') {

if (!agencyPhysicalAddress || typeof agencyPhysicalAddress !== 'string') {
next(
ApiError.notFound(`agencyPhysicalAddress does not exist or is invalid`),
);
return;
}

if (!agencyWorkerPhone || typeof agencyWorkerPhone !== 'string') {
next(ApiError.notFound(`agencyWorkerPhone does not exist or is invalid`));
return;
}
if (!agencyWorkerEmail || typeof agencyWorkerEmail === 'string') {
if (!agencyWorkerEmail || typeof agencyWorkerEmail !== 'string') {
next(ApiError.notFound(`agencyWorkerEmail does not exist or is invalid`));
return;
}
Expand All @@ -272,55 +269,44 @@ const createRequest = async (
return;
}

if (isFirstReferral !== true && isFirstReferral !== false) {
if (typeof isFirstReferral !== 'boolean') {
next(ApiError.notFound(`isFirstReferral does not exist or is invalid`));
return;
}
if (agreeFeedback !== true && agreeFeedback !== false) {
if (typeof agreeFeedback !== 'boolean') {
next(ApiError.notFound(`agreeFeedback does not exist or is invalid`));
return;
}
if (!requestedDate || !(requestedDate instanceof Date)) {
next(ApiError.notFound(`requestedDate does not exist or is invalid`));
return;
}
if (!status || typeof status === 'string') {
next(ApiError.notFound(`status does not exist or is invalid`));
return;
}
if (status !== 'Pending' && status !== 'Approved' && status !== 'Delivered') {
next(ApiError.notFound(`status is invalid`));
return;
}
if (!deliveryDate || !(deliveryDate instanceof Date)) {
next(ApiError.notFound(`deliveryDate does not exist or is invalid`));
if (typeof agreeLiability !== 'boolean') {
next(ApiError.notFound(`agreeLiability does not exist or is invalid`));
return;
}

try {
const user = await createBirthdayRequestByID(
const birthdayRequest = await createBirthdayRequestByID({
chapterId,
deadlineDate,
childBirthday,
childAge,
childName,
childAge,
childGender,
childRace,
childInterests,
giftSuggestions,
childAllergies,
allergyDetails,
giftSuggestions,
additionalInfo,
childSituation,
agencyWorkerName,
agencyOrganization,
agencyWorkerPhone,
agencyWorkerEmail,
agencyPhysicalAddress,
isFirstReferral,
agreeFeedback,
requestedDate,
status,
deliveryDate,
);
res.sendStatus(StatusCode.CREATED);
agreeLiability,
});
res.sendStatus(StatusCode.CREATED).json(birthdayRequest);
} catch (err) {
next(ApiError.internal('Unable to register user.'));
}
Expand Down
Loading

0 comments on commit d98fa35

Please sign in to comment.