UNPKG

@dvsa/smc-encounter-schema

Version:

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

1 lines 1.73 kB
'use strict';var classValidator=require('class-validator');var p=Object.defineProperty;var a=(r,e)=>p(r,"name",{value:e,configurable:true});var E=(r,e,i,t)=>{for(var n=e,s=r.length-1,l;s>=0;s--)(l=r[s])&&(n=(l(n))||n);return n};var f=class r{static{a(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"}};exports.MandatoryFieldConstraint=class o{validate(e,i){let t=i.constraints[0],n=f.getInstance(),s=n.getEncounterType(),l=n.getExaminerOfficerType();return t.level===0||t.exceptions?.includes(s)||t.level!==void 0&&t.level>s||t.roles?.length&&!t.roles.includes(l)&&!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((c,g)=>c==null?false:Object.entries(c).every(([x,u])=>typeof u=="string"?u.trim().length>0:u!=null)):true}};a(exports.MandatoryFieldConstraint,"MandatoryFieldConstraint"),exports.MandatoryFieldConstraint=E([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],exports.MandatoryFieldConstraint);function P(r,e){return (i,t)=>{classValidator.registerDecorator({name:"MandatoryField",target:i.constructor,propertyName:t,constraints:[r],options:e,validator:exports.MandatoryFieldConstraint});}}a(P,"MandatoryField");exports.MandatoryField=P;