@dvsa/smc-encounter-schema
Version:
Schemas required for Encounter submission as well as custom validators ## Developing ### Pre-requisites
1 lines • 2.23 kB
JavaScript
;var classValidator=require('class-validator');var T=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var E=(t,e)=>T(t,"name",{value:e,configurable:true});var i=(t,e,s,r)=>{for(var n=r>1?void 0:r?A(e,s):e,p=t.length-1,f;p>=0;p--)(f=t[p])&&(n=(r?f(e,s,n):f(n))||n);return r&&n&&T(e,s,n),n};var a=class t{static{E(this,"CurrentEncounterLevel");}static instance;level;officerType;requestType;constructor(){this.level=1,this.officerType="ANY",this.requestType="C";}static getInstance(){return t.instance||(t.instance=new t),t.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 l=class{validate(e,s){let r=s.constraints[0],n=a.getInstance(),p=n.getEncounterType(),f=n.getExaminerOfficerType();return r.level===0||r.exceptions?.includes(p)||r.level!==void 0&&r.level>p||r.roles?.length&&!r.roles.includes(f)&&!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((m,g)=>m==null?false:Object.entries(m).every(([L,c])=>typeof c=="string"?c.trim().length>0:c!=null)):true}};E(l,"MandatoryFieldConstraint"),l=i([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],l);function u(t,e){return (s,r)=>{classValidator.registerDecorator({name:"MandatoryField",target:s.constructor,propertyName:r,constraints:[t],options:e,validator:l});}}E(u,"MandatoryField");var o=class{static{E(this,"ContactType");}ctyNumber;ctyDescription;deletionMarker;updateInd;multipleInd;sortSequence};i([u({level:4},{groups:["createEncounter"]})],o.prototype,"ctyNumber",2),i([u({level:4},{groups:["createEncounter"]})],o.prototype,"ctyDescription",2),i([u({level:4},{groups:["createEncounter"]})],o.prototype,"deletionMarker",2),i([u({level:4},{groups:["createEncounter"]})],o.prototype,"updateInd",2),i([u({level:4},{groups:["createEncounter"]})],o.prototype,"multipleInd",2),i([u({level:4},{groups:["createEncounter"]})],o.prototype,"sortSequence",2);exports.ContactType=o;