UNPKG

@dvsa/smc-encounter-schema

Version:

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

1 lines 3.06 kB
'use strict';var classTransformer=require('class-transformer'),classValidator=require('class-validator');var N=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var n=(t,e)=>N(t,"name",{value:e,configurable:true});var i=(t,e,o,r)=>{for(var s=r>1?void 0:r?x(e,o):e,u=t.length-1,c;u>=0;u--)(c=t[u])&&(s=(r?c(e,o,s):c(s))||s);return r&&s&&N(e,o,s),s};var T=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,o){let r=o.constraints[0],s=T.getInstance(),u=s.getEncounterType(),c=s.getExaminerOfficerType();return r.level===0||r.exceptions?.includes(u)||r.level!==void 0&&r.level>u||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((A,b)=>A==null?false:Object.entries(A).every(([h,m])=>typeof m=="string"?m.trim().length>0:m!=null)):true}};n(a,"MandatoryFieldConstraint"),a=i([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],a);function E(t,e){return (o,r)=>{classValidator.registerDecorator({name:"MandatoryField",target:o.constructor,propertyName:r,constraints:[t],options:e,validator:a});}}n(E,"MandatoryField");var l=class{validate(e,o){return e==null?true:/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(e)}defaultMessage(e){return `${e.property} must match format YYYY-MM-DD HH:mm:ss`}};n(l,"UKDateFormatValidator"),l=i([classValidator.ValidatorConstraint({name:"ValidateUKDateFormat",async:false})],l);function O(t){return (e,o)=>{classValidator.registerDecorator({name:"ValidateUKDateFormat",target:e.constructor,propertyName:o,options:t,validator:l});}}n(O,"ValidateUKDateFormat");var f=class{static{n(this,"CommonDeletion");}description;deletionMarker};i([E({level:4},{groups:["createEncounter"]})],f.prototype,"description",2),i([E({level:4},{groups:["createEncounter"]})],f.prototype,"deletionMarker",2);var p=class extends f{static{n(this,"RoadWorthinessCheckItem");}checklistItem;effectiveFrom;effectiveTo};i([classValidator.IsOptional()],p.prototype,"checklistItem",2),i([O({groups:["createEncounter"]}),classValidator.IsOptional()],p.prototype,"effectiveFrom",2),i([O({groups:["createEncounter"]}),classValidator.IsOptional()],p.prototype,"effectiveTo",2);var d=class{static{n(this,"RoadWorthinessCheckList");}checkStatus;checklistItem};i([E({level:4},{groups:["createEncounter"]})],d.prototype,"checkStatus",2),i([classValidator.ValidateNested(),classTransformer.Type(()=>p),E({level:4},{groups:["createEncounter"]})],d.prototype,"checklistItem",2);exports.RoadWorthinessCheckList=d;