UNPKG

@dvsa/smc-encounter-schema

Version:

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

1 lines 2.78 kB
'use strict';var classTransformer=require('class-transformer'),classValidator=require('class-validator');var N=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var n=(t,e)=>N(t,"name",{value:e,configurable:true});var i=(t,e,s,r)=>{for(var o=r>1?void 0:r?O(e,s):e,p=t.length-1,c;p>=0;p--)(c=t[p])&&(o=(r?c(e,s,o):c(o))||o);return r&&o&&N(e,s,o),o};var m=class t{static{n(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],o=m.getInstance(),p=o.getEncounterType(),c=o.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,V)=>y==null?false:Object.entries(y).every(([F,f])=>typeof f=="string"?f.trim().length>0:f!=null)):true}};n(l,"MandatoryFieldConstraint"),l=i([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],l);function a(t,e){return (s,r)=>{classValidator.registerDecorator({name:"MandatoryField",target:s.constructor,propertyName:r,constraints:[t],options:e,validator:l});}}n(a,"MandatoryField");function d(t){return (e,s)=>{classValidator.registerDecorator({name:"isNullableString",target:e.constructor,propertyName:s,options:t,validator:{validate(r,o){return r===null||typeof r=="string"},defaultMessage(r){return `${r.property} must be a string or null`}}});}}n(d,"IsNullableString");var E=class{static{n(this,"CommonDescription");}code;description};i([d()],E.prototype,"code",2),i([d()],E.prototype,"description",2);var u=class extends E{static{n(this,"CapturedEthnicity");}category;deletionMarker;sequenceNumber};i([a({level:4},{groups:["createEncounter"]})],u.prototype,"category",2),i([a({level:4},{groups:["createEncounter"]})],u.prototype,"deletionMarker",2),i([a({level:4},{groups:["createEncounter"]})],u.prototype,"sequenceNumber",2);var T=class{static{n(this,"ObservedEthnicityInfo");}statedNumberOfDriver;capturedEthnicity};i([a({level:4},{groups:["createEncounter"]})],T.prototype,"statedNumberOfDriver",2),i([classValidator.ValidateNested(),classTransformer.Type(()=>u),a({level:4},{groups:["createEncounter"]})],T.prototype,"capturedEthnicity",2);exports.ObservedEthnicityInfo=T;