-
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.
Merge pull request #45 from lilith/mv-uility-funcs
Mv uility funcs
- Loading branch information
Showing
19 changed files
with
577 additions
and
269 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
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,54 @@ | ||
import { PrismaClient, Pronoun, type User } from '@prisma/client'; | ||
import { error } from '@sveltejs/kit'; | ||
const prisma = new PrismaClient(); | ||
import sanitizerFunc from 'sanitize'; | ||
|
||
const sanitizer = sanitizerFunc(); | ||
|
||
type PRONOUNS_ENUM = keyof typeof Pronoun; | ||
|
||
export const getParams = (url: URL, paramNames: string[]) => { | ||
const params = paramNames.map((x) => url.searchParams.get(x)).filter(Boolean) as string[]; | ||
if (params.length < paramNames.length) return null; | ||
return params; | ||
}; | ||
|
||
const sanitize = (input: string) => sanitizer.value(input, 'str'); | ||
|
||
export const circleNotif = async (schedDiffs: string, user: User) => { | ||
const sanitizedSchedDiffs = sanitize(schedDiffs); | ||
let objectivePronoun = Pronoun[user.pronouns as PRONOUNS_ENUM].split('_')[2]; | ||
const { SHE_HER_HERS, THEY_THEM_THEIRS, XE_XEM_XYRS, ZEZIE_HIR_HIRS } = Pronoun; | ||
// turn from possessive noun to possessive adjective | ||
switch (user.pronouns) { | ||
case SHE_HER_HERS: | ||
case THEY_THEM_THEIRS: | ||
case XE_XEM_XYRS: | ||
case ZEZIE_HIR_HIRS: | ||
objectivePronoun = objectivePronoun.slice(0, -1).toLowerCase(); | ||
} | ||
|
||
let kidNames = ''; | ||
|
||
if (!user.householdId) { | ||
throw error(400, { | ||
message: | ||
'You need to be part of a household in order to send notifs about your updated calendar' | ||
}); | ||
} | ||
const kids = await prisma.householdChild.findMany({ | ||
where: { | ||
householdId: user.householdId | ||
} | ||
}); | ||
|
||
kidNames = kids | ||
.map((kid) => `${kid.firstName}${kid.lastName ? ` ${kid.lastName}` : ''}`) | ||
.join(', '); | ||
|
||
return `${user.firstName}${ | ||
user.lastName && user.lastName.length ? ` ${user.lastName}` : '' | ||
} (parent of ${kidNames}) has updated ${objectivePronoun} tentative schedule:\nLegend: 🏠(host) 🚗(visit) 👤(dropoff) 👥(together) 🏫(at school) ⭐(good) 🌟(great) 🙏(needed)\n\n${sanitizedSchedDiffs}`; | ||
}; | ||
|
||
export const dateNotes = (notes: string) => sanitize(notes); |
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
Oops, something went wrong.