UNPKG

@dvsa/smc-encounter-schema

Version:

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

1 lines 2.01 kB
'use strict';var classValidator=require('class-validator');var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var o=(r,e)=>m(r,"name",{value:e,configurable:true});var E=(r,e,i,t)=>{for(var n=t>1?void 0:t?y(e,i):e,l=r.length-1,u;l>=0;l--)(u=r[l])&&(n=(t?u(e,i,n):u(n))||n);return t&&n&&m(e,i,n),n};var f=class r{static{o(this,"CurrentEncounterLevel");}static instance;level;officerType;requestType;constructor(){this.level=1,this.officerType="ANY",this.requestType="C";}static getInstance(){return r.instance||(r.instance=new r),r.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 s=class{validate(e,i){let t=i.constraints[0],n=f.getInstance(),l=n.getEncounterType(),u=n.getExaminerOfficerType();return t.level===0||t.exceptions?.includes(l)||t.level!==void 0&&t.level>l||t.roles?.length&&!t.roles.includes(u)&&!t.roles.includes("ANY")?true:e==null?false:typeof e=="string"?t.allowEmpty?true:e.trim().length>0:Array.isArray(e)?e.length===0?false:e.every((T,d)=>T==null?false:Object.entries(T).every(([N,a])=>typeof a=="string"?a.trim().length>0:a!=null)):true}};o(s,"MandatoryFieldConstraint"),s=E([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],s);function c(r,e){return (i,t)=>{classValidator.registerDecorator({name:"MandatoryField",target:i.constructor,propertyName:t,constraints:[r],options:e,validator:s});}}o(c,"MandatoryField");var p=class{static{o(this,"LicenceTypeCode");}licenceTypeCode;licenceTypeDescription;deletionMarker};E([c({level:4},{groups:["createEncounter"]})],p.prototype,"licenceTypeCode",2),E([c({level:4},{groups:["createEncounter"]})],p.prototype,"licenceTypeDescription",2),E([c({level:4},{groups:["createEncounter"]})],p.prototype,"deletionMarker",2);exports.LicenceTypeCode=p;