Skip to content
Snippets Groups Projects
Commit c5d757f8 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira
Browse files

Merge branch '22-criar-classe-resposta-de-fomulario-e-resposta-de-input' into 'develop'

Resolve "Criar Classe Resposta de Fomulario e Resposta de input"

Closes #22

See merge request !18
parents 65aa08e0 117eca52
No related branches found
No related tags found
2 merge requests!33Develop,!18Resolve "Criar Classe Resposta de Fomulario e Resposta de input"
Pipeline #20238 passed
......@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
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).
## 0.0.16 - 06-05-2019
### Added
- A FormsAnswer Class to store answers from forms #22 (Horstmann)
- A inputsAnswer Class to be the answer for each input in form #22 (Horstmann)
### Changed
- Form's constructor documentation
- Input's constructor documentation
## 0.0.15 - 26-04-2019
### Added
- A QueryOptions interface, that is used on dbHandler's executeQuery #20
......
{
"name": "form-creator-api",
"version": "0.0.15",
"version": "0.0.16",
"description": "RESTful API used to manage and answer forms.",
"main": "index.js",
"scripts": {
......
......@@ -50,11 +50,8 @@ export class Form {
public readonly inputs: Input[];
/**
* Creates a new instance of Input Class
* @param title - Form's title.
* @param description - Form's description
* @param inputs - Forms's question
* @param id - Form's identifier
* Creates a new instance of Form Class
* @param options - FormOptions instance to create a form.
*/
constructor(options: FormOptions) {
this.id = options.id ? options.id : null;
......
/*
* form-creator-api. RESTful API to manage and answer forms.
* Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of form-creator-api.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* form-creator-api. RESTful API to manage and answer forms.
* Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of form-creator-api.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { OptHandler } from "../utils/optHandler";
import { Form } from "./form";
import { InputAnswer, InputAnswerDict, InputAnswerOptions } from "./inputAnswer";
/** Parameters used to create a FormAnswer object. */
export interface FormAnswerOptions {
/** Unique identifier of a FormAnswer instance */
id?: number;
/** Form which answer is related to */
form: Form;
/** Time when it is answered */
timestamp: Date;
/** A dictionary of inputsAnswers. containing the answers */
inputsAnswer: InputAnswerDict;
}
/**
* Form Class to manage project's forms
*/
export class FormAnswer {
/** Unique identifier of a FormAnswer instance */
public readonly id: number;
/** Form which answer is related to */
public readonly form: Form;
/** Time when it is answered */
public readonly timestamp: Date;
/** Array of inputsAnswer. containing the answers */
public readonly inputAnswers: InputAnswer[];
/**
* Creates a new instance of FormAnswer Class
* @param options - FormAnswerOptions instance to create a FormAnswer.
*/
constructor(options: FormAnswerOptions) {
this.id = options.id ? options.id : null;
this.form = options.form;
this.timestamp = options.timestamp;
this.inputAnswers = [];
for (const inputId of Object.keys(options.inputsAnswer)) {
const inputAnswerArray: InputAnswer[] = options.inputsAnswer[inputId].map((i: InputAnswer, p: number) => {
/** When a user answers it, it may not contain the placement and which input this answer is from
* so needs to check before create a InputAnswerOptions, and enumerate placement and inputsId in case this came from a POST
* Else if it came from a GET the DB already have the id, placement and idInput so needs to be equal DB
*/
const inputAnswerstmp: InputAnswerOptions = {
id: (i.id ? i.id : null)
, idInput: (i.idInput ? i.idInput : inputId)
, placement: (i.placement ? i.placement : p)
, value: i.value
};
return new InputAnswer(inputAnswerstmp);
});
this.inputAnswers = this.inputAnswers.concat(inputAnswerArray);
}
}
}
......@@ -65,14 +65,8 @@ export class Input {
/**
* Creates a new instance of Input Class
* @param placement - Question position in forms.
* @param description - Input description
* @param question - Input question of this input
* @param type - InputType
* @param validation - Array of Validation
* @param id - Input identifier
* @param options - InputOptions instance to create a input.
*/
constructor(options: InputOptions) {
this.id = options.id ? options.id : null;
this.placement = options.placement;
......
/*
* form-creator-api. RESTful API to manage and answer forms.
* Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of form-creator-api.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* form-creator-api. RESTful API to manage and answer forms.
* Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of form-creator-api.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Parameters used to create a input object. */
export interface InputAnswerOptions {
/** Unique identifier of a InputAnswer instance. */
id?: number;
/** Input id which this answer came from. */
idInput: number;
/** Place where answers should be (multivalored answers). */
placement: number;
/** Input's answer */
value: string;
}
/** Parameters used to create a dictionary to uses as an collection of answers. */
export interface InputAnswerDict {
/** A key is a identifier of a Input instance */
[key: number]: InputAnswerOptions[];
}
/**
* Input Class to manage project's inputs forms
*/
export class InputAnswer {
/** Unique identifier of a Input Answer instance. */
public readonly id: number;
/** A identifier of a Input instance. */
public readonly idInput: number;
/** Place where input should be in the form. */
public readonly placement: number;
/** Input's Description */
public readonly value: string;
/**
* Creates a new instance of InputAnswer Class
* @param options - InputOptionsAnswer instance to create a inputAnswer.
*/
constructor(options: InputAnswerOptions) {
this.id = options.id ? options.id : null;
this.idInput = options.idInput;
this.placement = options.placement;
this.value = options.value;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment