UNPKG

@dvsa/smc-encounter-schema

Version:

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

1 lines 3.25 kB
'use strict';var classTransformer=require('class-transformer'),classValidator=require('class-validator');var A=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var i=(t,e)=>A(t,"name",{value:e,configurable:true});var n=(t,e,o,r)=>{for(var s=r>1?void 0:r?N(e,o):e,f=t.length-1,u;f>=0;f--)(u=t[f])&&(s=(r?u(e,o,s):u(s))||s);return r&&s&&A(e,o,s),s};var T=class t{static{i(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 p=class{validate(e,o){let r=o.constraints[0],s=T.getInstance(),f=s.getEncounterType(),u=s.getExaminerOfficerType();return r.level===0||r.exceptions?.includes(f)||r.level!==void 0&&r.level>f||r.roles?.length&&!r.roles.includes(u)&&!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((g,b)=>g==null?false:Object.entries(g).every(([h,m])=>typeof m=="string"?m.trim().length>0:m!=null)):true}};i(p,"MandatoryFieldConstraint"),p=n([classValidator.ValidatorConstraint({name:"MandatoryField",async:false})],p);function E(t,e){return (o,r)=>{classValidator.registerDecorator({name:"MandatoryField",target:o.constructor,propertyName:r,constraints:[t],options:e,validator:p});}}i(E,"MandatoryField");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`}};i(a,"UKDateFormatValidator"),a=n([classValidator.ValidatorConstraint({name:"ValidateUKDateFormat",async:false})],a);function O(t){return (e,o)=>{classValidator.registerDecorator({name:"ValidateUKDateFormat",target:e.constructor,propertyName:o,options:t,validator:a});}}i(O,"ValidateUKDateFormat");var l=class{static{i(this,"DangerousCheckListItemDetailBase");}generatedNumber;checkListItem;questionText;sectionHeading;effectiveFromDate;effectiveToDate};n([E({level:4},{groups:["createEncounter"]})],l.prototype,"generatedNumber",2),n([E({level:4},{groups:["createEncounter"]})],l.prototype,"checkListItem",2),n([E({level:4},{groups:["createEncounter"]})],l.prototype,"questionText",2),n([E({level:4},{groups:["createEncounter"]})],l.prototype,"sectionHeading",2),n([O({groups:["createEncounter"]}),E({level:4},{groups:["createEncounter"]})],l.prototype,"effectiveFromDate",2),n([O({groups:["createEncounter"]}),classValidator.IsOptional()],l.prototype,"effectiveToDate",2);var c=class{static{i(this,"DangerousCheckListItemBase");}checkListItemDetail;name;description};n([classValidator.ValidateNested(),classTransformer.Type(()=>l),E({level:4},{groups:["createEncounter"]})],c.prototype,"checkListItemDetail",2),n([E({level:4},{groups:["createEncounter"]})],c.prototype,"name",2),n([E({level:4},{groups:["createEncounter"]})],c.prototype,"description",2);exports.DangerousCheckListItemBase=c;