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