2023-02-16 23:09:41 +09:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { GlobalEventService } from '@/core/GlobalEventService.js';
|
2023-01-12 21:02:26 +09:00
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
2018-11-15 04:15:42 +09:00
|
|
|
|
|
|
|
export const meta = {
|
2023-01-12 21:02:26 +09:00
|
|
|
tags: ['admin', 'role'],
|
2019-02-23 11:20:58 +09:00
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2018-11-15 04:15:42 +09:00
|
|
|
requireAdmin: true,
|
2022-02-19 14:05:32 +09:00
|
|
|
} as const;
|
2018-11-15 04:15:42 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
2023-01-15 20:52:53 +09:00
|
|
|
policies: {
|
2023-01-12 21:02:26 +09:00
|
|
|
type: 'object',
|
|
|
|
},
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2023-01-12 21:02:26 +09:00
|
|
|
required: [
|
2023-01-15 20:52:53 +09:00
|
|
|
'policies',
|
2023-01-12 21:02:26 +09:00
|
|
|
],
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2018-11-15 04:15:42 +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(
|
2023-01-12 21:02:26 +09:00
|
|
|
private metaService: MetaService,
|
2022-09-18 03:27:08 +09:00
|
|
|
private globalEventService: GlobalEventService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps) => {
|
2023-01-12 21:02:26 +09:00
|
|
|
await this.metaService.update({
|
2023-01-15 20:52:53 +09:00
|
|
|
policies: ps.policies,
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
2023-01-15 20:52:53 +09:00
|
|
|
this.globalEventService.publishInternalEvent('policiesUpdated', ps.policies);
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|