Commit 7adf76a4 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch '7-ler-escrever-formulario-da-base' into 'develop'

Resolve "Ler/Escrever formulário da base"

Closes #7

See merge request !7
parents 25427545 9673fa3b
Pipeline #19954 passed with stages
in 1 minute and 4 seconds
......@@ -5,6 +5,16 @@ 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.6 - 01-04-2019
### Changed
- Input class to match with database model (Add id and description) (Horstmann)
- Form class to match with database model (Remove version add description) (Horstmann)
- enumHandler to remove sides whitespaces (Horstmann)
### Added
- Create readForm method to read form from database #7 (Horstmann)
- Create readInput method to read input from database #7 (Horstmann)
- Create writeForm method to insert form into database (Horstmann)
- Comments to coverage ignore errors that are not reached on tests.
## 0.0.5 - 19-03-2019
### Changed
- Remove tslint-stylish from package.json, package is deprecated (Horstmann)
......
{
"name": "form-creator-api",
"version": "0.0.5",
"version": "0.0.6",
"description": "RESTful API used to manage and answer forms.",
"main": "index.js",
"scripts": {
......
......@@ -20,28 +20,32 @@
*/
import { Input } from "./input";
/**
* Form Class to manage project's forms
*/
export class Form {
/** Form Header, as name and propose */
public readonly header: string;
/** Unique identifier of a Form instance */
public readonly id: number;
/** Form's title. An human-understandable identifier. Not unique */
public readonly title: string;
/** Form Description, as propose */
public readonly description: string;
/** Array of input. containing question */
public readonly inputs: Input[];
/** Version, a incremental numbert */
public readonly version: number;
/**
* Creates a new instance of Input Class
* @param header - Forms's name and propose.
* @param title - Form's title.
* @param description - Form's description
* @param inputs - Forms's question
* @param version - Incremental version of Form
* @param id - Form's identifier
*/
constructor(header: string, inputs: Input[], version: number) {
this.header = header;
constructor(title: string, description: string, inputs: Input[], id?: number) {
this.id = id ? id : null;
this.title = title;
this.description = description;
this.inputs = inputs;
this.version = version;
}
}
......@@ -35,8 +35,12 @@ export interface Validation {
*/
export class Input {
/** Unique identifier of a Input instance. */
public readonly id: number;
/** Place where input should be in the form. */
public readonly placement: number;
/** Input's Description */
public readonly description: string;
/** Question of input */
public readonly question: string;
/** Type of input */
......@@ -47,12 +51,17 @@ 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
*/
constructor(placement: number, question: string, type: InputType, validation: Validation[]) {
constructor(placement: number, description: string, question: string, type: InputType, validation: Validation[], id?: number) {
this.id = id ? id : null;
this.placement = placement;
this.description = description;
this.question = question;
this.type = type;
this.validation = validation;
......
This diff is collapsed.
This diff is collapsed.
......@@ -68,7 +68,7 @@ export class EnumHandler {
* @returns - Matching InputType
*/
public static parseInputType(str: string): InputType {
str = str.toLocaleLowerCase();
str = str.toLocaleLowerCase().trimLeft().trimRight();
switch (str) {
case "text":
return InputType.TEXT;
......@@ -102,7 +102,7 @@ export class EnumHandler {
* @returns - Matching ValidationType
*/
public static parseValidationType(str: string): ValidationType {
str = str.toLocaleLowerCase();
str = str.toLocaleLowerCase().trimLeft().trimRight();
switch (str) {
case "mandatory":
return ValidationType.MANDATORY;
......
......@@ -27,7 +27,7 @@ import {ValidationHandler } from "./validationHandler";
describe("Validation Handler", () => {
it("should test when Input is mandatory", () => {
const validation: Validation[] = [{type: ValidationType.MANDATORY, arguments: []}];
const input = new Input (1, "Question", InputType.TEXT, validation);
const input = new Input (1, "Description", "Question", InputType.TEXT, validation);
expect(ValidationHandler.validateInput(input, "FOOL")).to.be.true;
expect(ValidationHandler.validateInput(input, "")).to.be.false;
......@@ -37,7 +37,7 @@ describe("Validation Handler", () => {
it("should test when Input has a regex", () => {
const validation: Validation[] = [{type: ValidationType.REGEX, arguments: ["\\d{5}-\\d{3}"]}];
const input = new Input (1, "Question", InputType.TEXT, validation);
const input = new Input (1, "Description", "Question", InputType.TEXT, validation);
expect(ValidationHandler.validateInput(input, "88888-888")).to.be.true;
expect(ValidationHandler.validateInput(input, "88888-88")).to.be.false;
......@@ -48,7 +48,7 @@ describe("Validation Handler", () => {
it("should test when Input has a minimum char number", () => {
const validation: Validation[] = [{type: ValidationType.MINCHAR, arguments: [5]}];
const input = new Input (1, "Question", InputType.TEXT, validation);
const input = new Input (1, "Description", "Question", InputType.TEXT, validation);
expect(ValidationHandler.validateInput(input, "12345")).to.be.true;
expect(ValidationHandler.validateInput(input, "123456")).to.be.true;
......@@ -59,7 +59,7 @@ describe("Validation Handler", () => {
});
it("should test when Input has a maximum char number", () => {
const validation: Validation[] = [{type: ValidationType.MAXCHAR, arguments: [5]}];
const input = new Input (1, "Question", InputType.TEXT, validation);
const input = new Input (1, "Description", "Question", InputType.TEXT, validation);
expect(ValidationHandler.validateInput(input, "1234")).to.be.true;
expect(ValidationHandler.validateInput(input, "12345")).to.be.true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment