2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { SwSubscriptionsRepository } from '@/models/index.js';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2021-08-21 14:47:18 +09:00
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
|
tags: ['account'],
|
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2022-06-10 07:25:20 +02:00
|
|
|
|
|
|
|
|
description: 'Unregister from receiving push notifications.',
|
2022-02-19 14:05:32 +09:00
|
|
|
} as const;
|
2021-08-21 14:47:18 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
endpoint: { type: 'string' },
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2022-02-19 14:05:32 +09:00
|
|
|
required: ['endpoint'],
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2021-08-21 14:47:18 +09:00
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.swSubscriptionsRepository)
|
|
|
|
|
private swSubscriptionsRepository: SwSubscriptionsRepository,
|
|
|
|
|
) {
|
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
|
await this.swSubscriptionsRepository.delete({
|
|
|
|
|
userId: me.id,
|
|
|
|
|
endpoint: ps.endpoint,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|