Skip to content

Commit

Permalink
add forHoursDrawer route
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Aug 3, 2023
1 parent d50197f commit 238b1a8
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/api/router/orgHours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,48 @@ export const orgHoursRouter = defineRouter({
})
return intervalResults
}),
forHoursDrawer: publicProcedure
.input(z.string().regex(getIdPrefixRegex('organization', 'orgLocation', 'orgService')))
.query(async ({ ctx, input }) => {
const whereId = (): Prisma.OrgHoursWhereInput => {
switch (true) {
case isIdFor('organization', input): {
return { organization: { id: input, ...isPublic } }
}
case isIdFor('orgLocation', input): {
return { orgLocation: { id: input, ...isPublic } }
}
case isIdFor('orgService', input): {
return { orgService: { id: input, ...isPublic } }
}
default: {
return {}
}
}
}

const result = await ctx.prisma.orgHours.findMany({
where: {
...whereId(),
},
select: { id: true, dayIndex: true, start: true, end: true, closed: true, tz: true },
orderBy: [{ dayIndex: 'asc' }, { start: 'asc' }],
})
const transformedResult = result.map(({ start, end, ...rest }) => {
return {
start: DateTime.fromJSDate(start, { zone: rest.tz ?? 'America/New_York' }).toISOTime({
suppressMilliseconds: true,
suppressSeconds: true,
includeOffset: false,
}),
end: DateTime.fromJSDate(end, { zone: rest.tz ?? 'America/New_York' }).toISOTime({
suppressMilliseconds: true,
suppressSeconds: true,
includeOffset: false,
}),
...rest,
}
})
return transformedResult
}),
})
62 changes: 62 additions & 0 deletions packages/ui/mockData/orgHours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,73 @@ export const orgHoursData = {
tz: 'America/New_York',
},
],
forHoursDrawer: [
{
start: '05:00',
end: '12:00',
id: 'ohrs_01GW2HT8BQ87EZJ6K9H5ME1W0M',
dayIndex: 1,
closed: false,
tz: 'America/Los_Angeles',
},
{
start: '13:00',
end: '16:00',
id: 'ohrs_01GW2HT8BQQ6GM1VYVXEZMR3HM',
dayIndex: 2,
closed: false,
tz: 'America/Los_Angeles',
},
{
start: '08:00',
end: '12:00',
id: 'ohrs_01GW2HT8BRB9V0GEP1BGWVNCGA',
dayIndex: 2,
closed: false,
tz: 'America/Los_Angeles',
},
{
start: '05:00',
end: '13:00',
id: 'ohrs_01GW2HT8BRXRB7QH0BTRVVE1XB',
dayIndex: 3,
closed: false,
tz: 'America/Los_Angeles',
},
{
start: '05:00',
end: '13:00',
id: 'ohrs_01GW2HT8BQKTD5Z92YSKHQ03PA',
dayIndex: 4,
closed: false,
tz: 'America/Los_Angeles',
},
{
start: '08:00',
end: '13:00',
id: 'ohrs_01GW2HT8BS0YGWY4J7KTX3C4VA',
dayIndex: 5,
closed: false,
tz: 'America/Los_Angeles',
},
{
start: '14:00',
end: '17:00',
id: 'ohrs_01GW2HT8BQX6XYNSVYH4S26MT0',
dayIndex: 5,
closed: false,
tz: 'America/Los_Angeles',
},
],
} satisfies MockDataObject<'orgHours'>

export const orgHours = {
forHoursDisplay: getTRPCMock({
path: ['orgHours', 'forHoursDisplay'],
response: orgHoursData.forHoursDisplay,
}),
forHoursDrawer: getTRPCMock({
path: ['orgHours', 'forHoursDrawer'],
response: orgHoursData.forHoursDrawer,
}),
} satisfies MockHandlerObject<'orgHours'>

0 comments on commit 238b1a8

Please sign in to comment.