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