diff --git a/CHANGELOG.md b/CHANGELOG.md index 523a244bca13a2ebc56c6f4bbfeae0bc5518cc79..1f8e3f36fbb2a290f40f481524080e0ae040871f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.2.3 - 29/04/2020 +## Changed +- Api to create a subform input without needing input ID from body #73 (Richard Heise) +- OptHandler to not return error when there's no input ID +- Subform in core/ to have an optional input ID + + ## 1.2.2 - 07-04-2020 ## Added - Route to return the number of answers in a form #72 (Richard Heise) diff --git a/package.json b/package.json index 9812c026a4716498ad0b3a789c3b655c7df3d728..2029fc4a52bd07d6fba45e43a2bcf6b37b232ef3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "form-creator-api", - "version": "1.2.2", + "version": "1.2.3", "description": "RESTful API used to manage and answer forms.", "main": "index.js", "scripts": { @@ -43,4 +43,4 @@ "tslint": "^5.13.1", "typedoc": "^0.14.1" } -} +} \ No newline at end of file diff --git a/src/core/subForm.ts b/src/core/subForm.ts index 2482576971356458e8040a8594831a1fea38cb1c..095fe7f7765d65ee35ab4f777cc1300b23f6afca 100644 --- a/src/core/subForm.ts +++ b/src/core/subForm.ts @@ -28,7 +28,7 @@ export interface SubFormOptions { id?: number; /** Input wich subForm is linked. */ - inputId: number; + inputId?: number; /** SubForm of a form. */ contentFormId: number; @@ -51,8 +51,8 @@ export class SubForm { * @param options - FormOptions instance to create a form. */ constructor(options: SubFormOptions) { - this.id = options.id ? options.id : null; - this.inputId = options.inputId; + this.id = options.id ? options.id : null; + this.inputId = options.inputId ? options.inputId : null; this.contentFormId = options.contentFormId; } } diff --git a/src/utils/optHandler.ts b/src/utils/optHandler.ts index b6639c4a5144b74b70cc8dbe3fe44ea60543ebdd..7209aad7128e2c17ee3ccecdfc6e886eb955dba4 100644 --- a/src/utils/optHandler.ts +++ b/src/utils/optHandler.ts @@ -27,8 +27,8 @@ import { InputAnswer, InputAnswerDict, InputAnswerOptions, InputAnswerOptionsDic import { InputUpdate, InputUpdateOptions } from "../core/inputUpdate"; import { SubForm, SubFormOptions } from "../core/subForm"; import { User, UserOptions } from "./../core/user"; -import { InputType, UpdateType} from "./enumHandler"; -import { ErrorHandler} from "./errorHandler"; +import { InputType, UpdateType } from "./enumHandler"; +import { ErrorHandler } from "./errorHandler"; /** * OptHandler to handle an object and transform into a Classoptions to be used in Class's constructor @@ -39,15 +39,15 @@ export class OptHandler { * @param obj - object that should be parsed. * @returns - An FormOptions instance. */ - public static form(obj: any): FormOptions{ + public static form(obj: any): FormOptions { - if (obj.title === undefined ){ + if (obj.title === undefined) { throw ErrorHandler.notFound("Form title"); } - if (obj.description === undefined){ + if (obj.description === undefined) { throw ErrorHandler.notFound("Form description"); } - if (obj.inputs === undefined || !(obj.inputs instanceof Array)){ + if (obj.inputs === undefined || !(obj.inputs instanceof Array)) { throw ErrorHandler.notFound("Form inputs"); } const option: FormOptions = { @@ -66,7 +66,7 @@ export class OptHandler { * @param obj - object that should be parsed. * @returns - An InputOptions instance. */ - public static input(obj: any): InputOptions{ + public static input(obj: any): InputOptions { if (obj.placement === undefined) { throw ErrorHandler.notFound("Input placement"); } @@ -88,7 +88,7 @@ export class OptHandler { let subForm: SubForm = null; if ((obj.subForm !== null) && (obj.subForm !== undefined)) { - subForm = new SubForm (OptHandler.subForm(obj.subForm)); + subForm = new SubForm(OptHandler.subForm(obj.subForm)); } const option: InputOptions = { @@ -99,7 +99,7 @@ export class OptHandler { enabled: obj.enabled, type: obj.type, validation: obj.validation.map((v: any) => { - return {type: v.type, arguments: v.arguments}; + return { type: v.type, arguments: v.arguments }; }), sugestions: [], subForm @@ -123,16 +123,16 @@ export class OptHandler { if (obj.form === undefined || !(obj.form instanceof Form)) { throw ErrorHandler.notFound("Form"); } - if (obj.timestamp === undefined || !(obj.timestamp instanceof Date)) { + if (obj.timestamp === undefined || !(obj.timestamp instanceof Date)) { throw ErrorHandler.notFound("Answer Date"); } - if (obj.inputsAnswerOptions === undefined ) { + if (obj.inputsAnswerOptions === undefined) { throw ErrorHandler.notFound("Input Answers"); } const inputsAnswerOptionsTmp: InputAnswerOptionsDict = {}; - for (const key of Object.keys(obj.inputsAnswerOptions)){ - inputsAnswerOptionsTmp[parseInt(key, 10)] = obj.inputsAnswerOptions[parseInt(key, 10)].map( (i: InputAnswerOptions) => { + for (const key of Object.keys(obj.inputsAnswerOptions)) { + inputsAnswerOptionsTmp[parseInt(key, 10)] = obj.inputsAnswerOptions[parseInt(key, 10)].map((i: InputAnswerOptions) => { return OptHandler.inputAnswer(i); }); } @@ -236,10 +236,10 @@ export class OptHandler { */ public static sugestion(obj: any): Sugestion { - if (typeof(obj.value) !== "string") { + if (typeof (obj.value) !== "string") { throw ErrorHandler.notFound("Sugestion value"); } - if (typeof(obj.placement) !== "number") { + if (typeof (obj.placement) !== "number") { throw ErrorHandler.notFound("Sugestion placement"); } @@ -264,7 +264,7 @@ export class OptHandler { throw ErrorHandler.notFound("email"); } - if (! hashedPw) { + if (!hashedPw) { const optionNoHash: UserOptions = { name: obj.name , email: obj.email @@ -287,9 +287,6 @@ export class OptHandler { } public static subForm(obj: any): SubForm { - if (obj.inputId === undefined) { - throw ErrorHandler.notFound("SubForm InputId"); - } if (obj.contentFormId === undefined) { throw ErrorHandler.notFound("SubForm ContentForm"); }