import { InitAction } from "../action/InitAction"; import { Context } from "../context/Context"; import { Logger } from "../logger/Logger"; import { ERuleTypes } from "../rules/enum/ERuleTypes"; import { IManager } from "./interface/IManager"; import { v4 as uuidv4 } from "uuid"; import { EActionStatus } from "../action/enum/EActionStatus"; import { EMessageType } from "../logger/enum/EMessageType"; import { EOperationStatus } from "../operation/enum/EOperationStatus"; import { BaseManager } from "./base/BaseManager"; import { CustomError } from "../exception/CustomError"; import { UnsubscribeActionParams } from "../action/type/UnsubscribeActionParams"; import { UnsubscribeRules } from "../rules/UnsubscribeRules"; import { UnsubscribeOperation } from "../operation/UnsubscribeOperation"; import { UnsubscribeAction } from "../action/UnsubscribeAction"; const parseError = require('parse-error'); export class UnsubscribeManager extends BaseManager implements IManager { constructor(action : UnsubscribeAction, context: Context){ super(action, context); } /*@overwrite*/ public async performAction(): Promise { return new Promise( async (resolve, reject)=>{ let params : UnsubscribeActionParams = Object.assign(this.getAction().getParams()); let validationRules = new UnsubscribeRules(params); validationRules.validate([ERuleTypes.IS_CLIENT_INIT], this.context); if(validationRules.passes){ try { let subscribeOperation = new UnsubscribeOperation(this.context); await subscribeOperation.handler(params); if(subscribeOperation.status == EOperationStatus.PERFORMED ){ this.action.status = EActionStatus.PERFORMED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Action "+this.action.type + " performaced", action: this.action, errors: validationRules.errors, type:EMessageType.INFO }); }else{ let errors : Array = []; if(subscribeOperation.errors) errors = [...errors, ...subscribeOperation.errors]; this.action.status = EActionStatus.FAILED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Something operations not performaced in action "+this.action.type, action: this.action, errors: errors, type: EMessageType.ERROR }); } } catch (error) { let errors = parseError(error); this.action.status = EActionStatus.FAILED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Something operations not performaced in action "+this.action.type, action: this.action, errors: errors, type: EMessageType.ERROR }); } }else{ this.action.status = EActionStatus.FAILED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Action "+this.action.type + " not performaced", action: this.action, errors: validationRules.errors, type: EMessageType.ERROR }); } resolve(this.action.status); }); } }