@dvsa/smc-encounter-schema
Version:
Schemas required for Encounter submission as well as custom validators ## Developing ### Pre-requisites
1 lines • 2.73 kB
JavaScript
;var classValidator=require('class-validator');var y=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var n=(r,e)=>y(r,"name",{value:e,configurable:true});var i=(r,e,o,t)=>{for(var s=t>1?void 0:t?N(e,o):e,p=r.length-1,c;p>=0;p--)(c=r[p])&&(s=(t?c(e,o,s):c(s))||s);return t&&s&&y(e,o,s),s};var a=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(a,"UKDateFormatValidator"),a=i([classValidator.ValidatorConstraint({name:"ValidateUKDateFormat",async:false})],a);function T(r){return (e,o)=>{classValidator.registerDecorator({name:"ValidateUKDateFormat",target:e.constructor,propertyName:o,options:r,validator:a});}}n(T,"ValidateUKDateFormat");var m=class r{static{n(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"}};var l=class{validate(e,o){let t=o.constraints[0],s=m.getInstance(),p=s.getEncounterType(),c=s.getExaminerOfficerType();return t.level===0||t.exceptions?.includes(p)||t.level!==void 0&&t.level>p||t.roles?.length&&!t.roles.includes(c)&&!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((O,I)=>O==null?false:Object.entries(O).every(([F,E])=>typeof E=="string"?E.trim().length>0:E!=null)):true}};n(l,"MandatoryFieldConstraint"),l=i([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],l);function d(r,e){return (o,t)=>{classValidator.registerDecorator({name:"MandatoryField",target:o.constructor,propertyName:t,constraints:[r],options:e,validator:l});}}n(d,"MandatoryField");var u=class{static{n(this,"CommonDeletion");}description;deletionMarker};i([d({level:4},{groups:["createEncounter"]})],u.prototype,"description",2),i([d({level:4},{groups:["createEncounter"]})],u.prototype,"deletionMarker",2);var f=class extends u{static{n(this,"RoadWorthinessCheckItem");}checklistItem;effectiveFrom;effectiveTo};i([classValidator.IsOptional()],f.prototype,"checklistItem",2),i([T({groups:["createEncounter"]}),classValidator.IsOptional()],f.prototype,"effectiveFrom",2),i([T({groups:["createEncounter"]}),classValidator.IsOptional()],f.prototype,"effectiveTo",2);exports.RoadWorthinessCheckItem=f;