1234567891011121314151617181920212223242526272829303132333435 |
- import Job from "@/Job";
- import EventsModule from "@/modules/EventsModule";
- import { JobOptions } from "@/types/JobOptions";
- export default class UnsubscribeMany extends Job {
- public constructor(
- payload?: any,
- options?: Omit<JobOptions, "runDirectly">
- ) {
- super(EventsModule, payload, options);
- }
- protected override async _validate() {
- if (typeof this._payload !== "object")
- throw new Error("Payload must be an object");
- if (!Array.isArray(this._payload.channels))
- throw new Error("Channels must be an array");
- this._payload.channels.forEach(channel => {
- if (typeof channel !== "string")
- throw new Error("Channel must be a string");
- });
- }
- protected override async _authorize() {}
- protected async _execute({ channels }: { channels: string[] }) {
- const socketId = this._context.getSocketId();
- if (!socketId) throw new Error("No socketId specified");
- await EventsModule.unsubscribeManySocket(channels, socketId);
- }
- }
|