UnsubscribeMany.ts 964 B

1234567891011121314151617181920212223242526272829303132333435
  1. import Job from "@/Job";
  2. import EventsModule from "@/modules/EventsModule";
  3. import { JobOptions } from "@/types/JobOptions";
  4. export default class UnsubscribeMany extends Job {
  5. public constructor(
  6. payload?: any,
  7. options?: Omit<JobOptions, "runDirectly">
  8. ) {
  9. super(EventsModule, payload, options);
  10. }
  11. protected override async _validate() {
  12. if (typeof this._payload !== "object")
  13. throw new Error("Payload must be an object");
  14. if (!Array.isArray(this._payload.channels))
  15. throw new Error("Channels must be an array");
  16. this._payload.channels.forEach(channel => {
  17. if (typeof channel !== "string")
  18. throw new Error("Channel must be a string");
  19. });
  20. }
  21. protected override async _authorize() {}
  22. protected async _execute({ channels }: { channels: string[] }) {
  23. const socketId = this._context.getSocketId();
  24. if (!socketId) throw new Error("No socketId specified");
  25. await EventsModule.unsubscribeManySocket(channels, socketId);
  26. }
  27. }