-
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.
- Loading branch information
1 parent
e147e13
commit f368e36
Showing
10 changed files
with
155 additions
and
2 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
8 changes: 8 additions & 0 deletions
8
prisma/migrations/20240711084258_add_guide_alarm/migration.sql
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,8 @@ | ||
-- CreateTable | ||
CREATE TABLE "GuideAlarm" ( | ||
"wfs" "WfsType" NOT NULL, | ||
"limit" INTEGER NOT NULL, | ||
"enabled" BOOLEAN NOT NULL DEFAULT true, | ||
|
||
CONSTRAINT "GuideAlarm_pkey" PRIMARY KEY ("wfs") | ||
); |
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,35 @@ | ||
import { GuideAlarm } from '@prisma/client'; | ||
import { FieldNode } from 'graphql'; | ||
import { prisma } from '../../prisma/db.js'; | ||
import { Resolvers, WfsType } from '../gen/index.js'; | ||
|
||
export const GuideAlarmResolver: Resolvers = { | ||
Query: { | ||
async guideAlarms(_parent, _args, _context, info) { | ||
// Get the wfs types to query for from the graphql info object | ||
const wfsTypesToQuery = | ||
((info.fieldNodes[0]?.selectionSet?.selections as FieldNode[]) | ||
.map((selection) => selection.name.value) | ||
.filter((wfs) => wfs !== '__typename') as WfsType[]) ?? []; | ||
|
||
const alarms = await prisma.guideAlarm.findMany({ | ||
where: { | ||
wfs: { | ||
in: wfsTypesToQuery, | ||
}, | ||
}, | ||
}); | ||
|
||
// Convert the array of alarms to an object with the wfs as the key | ||
return Object.fromEntries(alarms.map((alarm) => [alarm.wfs, alarm])) as Record<WfsType, GuideAlarm>; | ||
}, | ||
}, | ||
Mutation: { | ||
updateGuideAlarm(_parent, args) { | ||
return prisma.guideAlarm.update({ | ||
where: { wfs: args.wfs }, | ||
data: args, | ||
}); | ||
}, | ||
}, | ||
}; |
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,24 @@ | ||
export const GuideAlarmTypeDefs = `#graphql | ||
type GuideAlarm { | ||
limit: Int! | ||
enabled: Boolean! | ||
} | ||
type GuideAlarms { | ||
OIWFS: GuideAlarm! | ||
PWFS1: GuideAlarm! | ||
PWFS2: GuideAlarm! | ||
} | ||
type Query { | ||
guideAlarms: GuideAlarms! | ||
} | ||
type Mutation { | ||
updateGuideAlarm( | ||
wfs: WfsType! | ||
limit: Int | ||
enabled: Boolean | ||
): GuideAlarm! | ||
} | ||
`; |
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,19 @@ | ||
import { Prisma } from '@prisma/client'; | ||
|
||
export const INITIAL_GUIDE_ALARMS: Prisma.GuideAlarmCreateInput[] = [ | ||
{ | ||
wfs: 'PWFS1', | ||
limit: 900, | ||
enabled: true, | ||
}, | ||
{ | ||
wfs: 'PWFS2', | ||
limit: 900, | ||
enabled: true, | ||
}, | ||
{ | ||
wfs: 'OIWFS', | ||
limit: 900, | ||
enabled: true, | ||
}, | ||
]; |
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