hippofish/packages/backend/src/server/api/endpoints/sw/show-registration.ts

60 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-04-07 03:56:46 +02:00
import { SwSubscriptions } from "@/models/index.js";
import define from "../../define.js";
export const meta = {
2023-04-07 03:56:46 +02:00
tags: ["account"],
requireCredential: true,
2023-04-07 03:56:46 +02:00
description: "Check push notification registration exists.",
res: {
2023-04-07 03:56:46 +02:00
type: "object",
optional: false,
nullable: true,
properties: {
userId: {
2023-04-07 03:56:46 +02:00
type: "string",
optional: false,
nullable: false,
},
endpoint: {
2023-04-07 03:56:46 +02:00
type: "string",
optional: false,
nullable: false,
},
sendReadMessage: {
2023-04-07 03:56:46 +02:00
type: "boolean",
optional: false,
nullable: false,
},
},
},
} as const;
export const paramDef = {
2023-04-07 03:56:46 +02:00
type: "object",
properties: {
2023-04-07 03:56:46 +02:00
endpoint: { type: "string" },
},
2023-04-07 03:56:46 +02:00
required: ["endpoint"],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const subscription = await SwSubscriptions.findOneBy({
userId: me.id,
endpoint: ps.endpoint,
});
if (subscription != null) {
return {
userId: subscription.userId,
endpoint: subscription.endpoint,
sendReadMessage: subscription.sendReadMessage,
};
}
return null;
});