UNPKG

@dvsa/smc-encounter-schema

Version:

Schemas required for Encounter submission as well as custom validators ## Developing ### Pre-requisites

1 lines 3.85 kB
'use strict';var classTransformer=require('class-transformer'),classValidator=require('class-validator');var C=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var s=(i,e)=>C(i,"name",{value:e,configurable:true});var t=(i,e,l,r)=>{for(var o=r>1?void 0:r?b(e,l):e,m=i.length-1,p;m>=0;m--)(p=i[m])&&(o=(r?p(e,l,o):p(o))||o);return r&&o&&C(e,l,o),o};function f(i){return (e,l)=>{classValidator.registerDecorator({name:"isNullableNumber",target:e.constructor,propertyName:l,options:i,validator:{validate(r,o){return r===null||typeof r=="number"},defaultMessage(r){return `${r.property} must be a number or null`}}});}}s(f,"IsNullableNumber");var d=class i{static{s(this,"CurrentEncounterLevel");}static instance;level;officerType;requestType;constructor(){this.level=1,this.officerType="ANY",this.requestType="C";}static getInstance(){return i.instance||(i.instance=new i),i.instance}getEncounterType(){return this.level}setEncounterType(e){this.level=e;}getExaminerOfficerType(){return this.officerType}setExaminerOfficerType(e){this.officerType=e;}getRequestType(){return this.requestType}setRequestType(e){this.requestType=e;}isDeletedEncounter(){return this.requestType==="D"}};var a=class{validate(e,l){let r=l.constraints[0],o=d.getInstance(),m=o.getEncounterType(),p=o.getExaminerOfficerType();return r.level===0||r.exceptions?.includes(m)||r.level!==void 0&&r.level>m||r.roles?.length&&!r.roles.includes(p)&&!r.roles.includes("ANY")?true:e==null?false:typeof e=="string"?r.allowEmpty?true:e.trim().length>0:Array.isArray(e)?e.length===0?false:e.every((O,x)=>O==null?false:Object.entries(O).every(([I,c])=>typeof c=="string"?c.trim().length>0:c!=null)):true}};s(a,"MandatoryFieldConstraint"),a=t([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],a);function u(i,e){return (l,r)=>{classValidator.registerDecorator({name:"MandatoryField",target:l.constructor,propertyName:r,constraints:[i],options:e,validator:a});}}s(u,"MandatoryField");function g(i){return (e,l)=>{classValidator.registerDecorator({name:"isNullableString",target:e.constructor,propertyName:l,options:i,validator:{validate(r,o){return r===null||typeof r=="string"},defaultMessage(r){return `${r.property} must be a string or null`}}});}}s(g,"IsNullableString");var n=class{static{s(this,"NoticeType");}code;ntyDescription;currentCode;act;currentVersion;typeCode;ntyShortDescription;operatorCopy;driverRequired;translationAvailable;sequenceNumber;noticeTypeCategory;autoClosurePeriod;ntySummary;closeFlag;aevEventCodeClose;aevEventCodeClear;aevEventCodeReactivate;ettCode;notifiableFlag};t([classValidator.IsOptional()],n.prototype,"code",2),t([classValidator.IsOptional()],n.prototype,"ntyDescription",2),t([classValidator.IsOptional()],n.prototype,"currentCode",2),t([g()],n.prototype,"act",2),t([classValidator.IsOptional()],n.prototype,"currentVersion",2),t([classValidator.IsOptional()],n.prototype,"typeCode",2),t([u({level:4},{groups:["createEncounter"]})],n.prototype,"ntyShortDescription",2),t([classTransformer.Transform(({value:e})=>e!==null?Number.parseInt(e,10):null),u({level:4},{groups:["createEncounter"]})],n.prototype,"operatorCopy",2),t([u({level:4},{groups:["createEncounter"]})],n.prototype,"driverRequired",2),t([u({level:4},{groups:["createEncounter"]})],n.prototype,"translationAvailable",2),t([u({level:4},{groups:["createEncounter"]})],n.prototype,"sequenceNumber",2),t([g()],n.prototype,"noticeTypeCategory",2),t([f()],n.prototype,"autoClosurePeriod",2),t([classValidator.IsOptional()],n.prototype,"ntySummary",2),t([u({level:4},{groups:["createEncounter"]})],n.prototype,"closeFlag",2),t([f()],n.prototype,"aevEventCodeClose",2),t([f()],n.prototype,"aevEventCodeClear",2),t([f()],n.prototype,"aevEventCodeReactivate",2),t([g()],n.prototype,"ettCode",2),t([g()],n.prototype,"notifiableFlag",2);exports.NoticeType=n;