mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
extract notification repository to interface
This commit is contained in:
@@ -2,10 +2,7 @@ import { ShuttleGetterRepository } from "../../repositories/ShuttleGetterReposit
|
|||||||
import { TupleKey } from "../../types/TupleKey";
|
import { TupleKey } from "../../types/TupleKey";
|
||||||
import { IEta } from "../../entities/entities";
|
import { IEta } from "../../entities/entities";
|
||||||
import { AppleNotificationSender, NotificationAlertArguments } from "../senders/AppleNotificationSender";
|
import { AppleNotificationSender, NotificationAlertArguments } from "../senders/AppleNotificationSender";
|
||||||
import {
|
import { NotificationLookupArguments, ScheduledNotification } from "../../repositories/NotificationRepository";
|
||||||
NotificationLookupArguments,
|
|
||||||
ScheduledNotification
|
|
||||||
} from "../../repositories/NotificationRepository";
|
|
||||||
|
|
||||||
type DeviceIdSecondsThresholdAssociation = { [key: string]: number };
|
type DeviceIdSecondsThresholdAssociation = { [key: string]: number };
|
||||||
|
|
||||||
|
|||||||
19
src/repositories/InMemoryNotificationRepository.ts
Normal file
19
src/repositories/InMemoryNotificationRepository.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { NotificationLookupArguments, NotificationRepository, ScheduledNotification } from "./NotificationRepository";
|
||||||
|
|
||||||
|
export class InMemoryNotificationRepository implements NotificationRepository {
|
||||||
|
async getAllNotificationsForShuttleAndStopId(shuttleId: string, stopId: string) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSecondsThresholdForNotificationIfExists(lookupArguments: NotificationLookupArguments) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async addOrUpdateNotification(notification: ScheduledNotification) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteNotificationIfExists(lookupArguments: NotificationLookupArguments) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,20 +14,9 @@ export interface ScheduledNotification extends NotificationLookupArguments {
|
|||||||
secondsThreshold: number;
|
secondsThreshold: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NotificationRepository {
|
export interface NotificationRepository {
|
||||||
public async getAllNotificationsForShuttleAndStopId(shuttleId: string, stopId: string) {
|
getAllNotificationsForShuttleAndStopId(shuttleId: string, stopId: string): Promise<ScheduledNotification[]>;
|
||||||
|
getSecondsThresholdForNotificationIfExists(lookupArguments: NotificationLookupArguments): Promise<number>;
|
||||||
}
|
addOrUpdateNotification(notification: ScheduledNotification): Promise<void>;
|
||||||
|
deleteNotificationIfExists(lookupArguments: NotificationLookupArguments): Promise<void>;
|
||||||
public async getSecondsThresholdForNotificationIfExists(lookupArguments: NotificationLookupArguments) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async addOrUpdateNotification(notification: ScheduledNotification) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async deleteNotificationIfExists(lookupArguments: NotificationLookupArguments) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { NotificationResponse, Resolvers } from "../generated/graphql";
|
|||||||
import { ServerContext } from "../ServerContext";
|
import { ServerContext } from "../ServerContext";
|
||||||
import {
|
import {
|
||||||
ETANotificationScheduler,
|
ETANotificationScheduler,
|
||||||
ScheduledNotification
|
|
||||||
} from "../notifications/schedulers/ETANotificationScheduler";
|
} from "../notifications/schedulers/ETANotificationScheduler";
|
||||||
|
import { ScheduledNotification } from "../repositories/NotificationRepository";
|
||||||
|
|
||||||
export const MutationResolvers: Resolvers<ServerContext> = {
|
export const MutationResolvers: Resolvers<ServerContext> = {
|
||||||
Mutation: {
|
Mutation: {
|
||||||
@@ -23,7 +23,7 @@ export const MutationResolvers: Resolvers<ServerContext> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const notificationData: NotificationSchedulingArguments = {
|
const notificationData: ScheduledNotification = {
|
||||||
...args.input,
|
...args.input,
|
||||||
secondsThreshold: typeof args.input.secondsThreshold === 'number'
|
secondsThreshold: typeof args.input.secondsThreshold === 'number'
|
||||||
? args.input.secondsThreshold
|
? args.input.secondsThreshold
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it } from "@jest/globals";
|
import { describe, it } from "@jest/globals";
|
||||||
|
|
||||||
describe("NotificationRepository", () => {
|
describe("InMemoryNotificationRepository", () => {
|
||||||
describe("getAllNotificationsForShuttleAndStopId", () => {
|
describe("getAllNotificationsForShuttleAndStopId", () => {
|
||||||
it("gets notifications correctly", async () => {
|
it("gets notifications correctly", async () => {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user