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