UNPKG

@dvsa/smc-encounter-schema

Version:

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

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