UNPKG

@dvsa/smc-encounter-schema

Version:

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

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