Skip to content
Snippets Groups Projects
Commit c4b19b21 authored by Gianfranco Harres's avatar Gianfranco Harres
Browse files

Merge branch 'issue/60-Assign-route' into 'develop'

Issue #60: Add route to assign users to forms

See merge request !58
parents 7d002c61 61727fb2
Branches
No related tags found
2 merge requests!65Stable version 1.2,!58Issue #60: Add route to assign users to forms
Pipeline #22703 passed
...@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. ...@@ -4,6 +4,13 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 1.1.8 - 30-01-2020
### Added
- Route to assign users to forms #60 (Richard Heise)
## Changed
- Route to write a form now has an extra stage in the waterfall
- THis stage assigns the user to a form by ID
## 1.1.7 - 29-01-2020 ## 1.1.7 - 29-01-2020
### Added ### Added
- Function to assign users to forms #54 (Gianfranco) - Function to assign users to forms #54 (Gianfranco)
......
{ {
"name": "form-creator-api", "name": "form-creator-api",
"version": "1.1.7", "version": "1.1.8",
"description": "RESTful API used to manage and answer forms.", "description": "RESTful API used to manage and answer forms.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
...@@ -55,6 +55,7 @@ before(function (done): void { ...@@ -55,6 +55,7 @@ before(function (done): void {
export let testToken: string; export let testToken: string;
describe("Initial test User", () => {
it ("Should respond 200 when signing up a valid user", (done) => { it ("Should respond 200 when signing up a valid user", (done) => {
request(server) request(server)
.post("/user/signUp") .post("/user/signUp")
...@@ -88,6 +89,8 @@ it("Should respond 200 when validating an user signIn", (done) => { ...@@ -88,6 +89,8 @@ it("Should respond 200 when validating an user signIn", (done) => {
}) })
.end(done); .end(done);
}); });
})
describe("API data controller - form", () => { describe("API data controller - form", () => {
it("should respond 200 when getting a list of forms", (done) => { it("should respond 200 when getting a list of forms", (done) => {
......
...@@ -96,12 +96,30 @@ export class FormCtrl { ...@@ -96,12 +96,30 @@ export class FormCtrl {
callback(null, formUpdate); callback(null, formUpdate);
}); });
}, },
(formUpdate: FormUpdate, callback: (err: Error, formId: number) => void) => { (formUpdate: FormUpdate, callback: (err: Error, formId?: number) => void) => {
req.db.form.update(formUpdate, (err: Error) => { req.db.form.update(formUpdate, (err: Error) => {
callback(err, formUpdate.form.id);
if (err) {
callback(err);
return;
}
callback(null, formUpdate.form.id);
}); });
},
(formId: number, callback: (err: Error) => void) => {
/** req.userData has to be parsed into an object so we can get its ID */
req.db.user.assign(Object(req.userData).id, formId, (err: Error) => {
if (err) {
callback(err);
return;
} }
], (err, resultId) => {
callback(null);
});
}
], (err) => {
if (err) { if (err) {
res.status(500).json({ res.status(500).json({
message: "Could not insert form. Some error has occurred. Check error property for details." message: "Could not insert form. Some error has occurred. Check error property for details."
...@@ -111,8 +129,7 @@ export class FormCtrl { ...@@ -111,8 +129,7 @@ export class FormCtrl {
} }
res.json({ res.json({
id: resultId message: "Form added."
, message: "Form added. Id on key 'id'"
}); });
return; return;
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment