diff --git a/src/controllers/qualification.controller.js b/src/controllers/qualification.controller.js index 9b28c82f..d53c6e85 100644 --- a/src/controllers/qualification.controller.js +++ b/src/controllers/qualification.controller.js @@ -1,17 +1,25 @@ +import {Project, Qualification, QualificationMock} from "../models/index.js"; + export const create = (req, res) => { res.json({ message: 'Not Yet Implemented', }); }; -export const findAll = (req, res) => { - res.json({ - message: 'Not Yet Implemented', - }); +export const findAll = async (req, res) => { + if (req.query.useMock) { + res.json(QualificationMock.findAll()); + return; + } + + res.json(await Qualification.findAll()); }; -export const findOne = (req, res) => { - res.json({ - message: 'Not Yet Implemented', - }); +export const findOne = async (req, res) => { + if (req.query.useMock) { + res.json(QualificationMock.findOne(req.query.id)); + return; + } + + res.json(await Qualification.findByPk(req.query.id)); }; export const update = (req, res) => { res.json({ diff --git a/src/models/qualifications/qualifications.model.js b/src/models/qualifications/qualifications.model.js index f04d3a02..59aada64 100644 --- a/src/models/qualifications/qualifications.model.js +++ b/src/models/qualifications/qualifications.model.js @@ -1,9 +1,25 @@ 'use strict'; +import Sequelize from 'sequelize'; +const { DataTypes, Model } = Sequelize; +import { sequelize } from '../database'; -class Qualification { - static list(page = 0, limit = 10) { - return stub; - } -} +class Qualification extends Model { } + +Qualification.init({ + id: { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV1, + primaryKey: true, + }, + project_id: DataTypes.STRING, + qualification_type: DataTypes.STRING, + label: DataTypes.STRING, + crediting_start_date: DataTypes.STRING, + crediting_end_date: DataTypes.STRING, + validity_start_date: DataTypes.STRING, + validity_end_date: DataTypes.STRING, + unit_quality: DataTypes.STRING, + qualification_link: DataTypes.STRING, +}, { sequelize, modelName: 'qualification' }); export { Qualification }; diff --git a/src/models/qualifications/qualifications.stub.json b/src/models/qualifications/qualifications.stub.json index fe51488c..647a2f6c 100644 --- a/src/models/qualifications/qualifications.stub.json +++ b/src/models/qualifications/qualifications.stub.json @@ -1 +1,62 @@ -[] +[ + { + "id": "1", + "project_id": 1, + "qualification_type": "basic type", + "label": "qualification 1", + "crediting_start_date": "2011-10-05T14:48:00.000Z", + "crediting_end_date": "2022-10-05T14:48:00.000Z", + "validity_start_date": "2011-11-05T14:41:00.000Z", + "validity_end_date": "2022-11-05T14:41:00.000Z", + "unit_quality": "good", + "qualification_link": "https://qualification.link/1" + }, + { + "id": "2", + "project_id": 1, + "qualification_type": "basic type", + "label": "qualification 2", + "crediting_start_date": "2001-10-05T14:48:00.000Z", + "crediting_end_date": "2002-10-05T14:48:00.000Z", + "validity_start_date": "2001-11-05T14:41:00.000Z", + "validity_end_date": "2002-11-05T14:41:00.000Z", + "unit_quality": "average", + "qualification_link": "https://qualification.link/2" + }, + { + "id": "3", + "project_id": 1, + "qualification_type": "advanced type", + "label": "qualification 3", + "crediting_start_date": "2005-10-05T14:48:00.000Z", + "crediting_end_date": "2007-10-05T14:48:00.000Z", + "validity_start_date": "2005-11-05T14:41:00.000Z", + "validity_end_date": "2007-11-05T14:41:00.000Z", + "unit_quality": "average", + "qualification_link": "https://qualification.link/3" + }, + { + "id": "4", + "project_id": 1, + "qualification_type": "advanced type", + "label": "qualification 4", + "crediting_start_date": "2015-10-05T14:48:00.000Z", + "crediting_end_date": "2017-10-05T14:48:00.000Z", + "validity_start_date": "2015-11-05T14:41:00.000Z", + "validity_end_date": "2017-11-05T14:41:00.000Z", + "unit_quality": "average", + "qualification_link": "https://qualification.link/4" + }, + { + "id": "5", + "project_id": 1, + "qualification_type": "special type", + "label": "qualification 5", + "crediting_start_date": "2035-10-05T14:48:00.000Z", + "crediting_end_date": "2037-10-05T14:48:00.000Z", + "validity_start_date": "2035-11-05T14:41:00.000Z", + "validity_end_date": "2037-11-05T14:41:00.000Z", + "unit_quality": "fair", + "qualification_link": "https://qualification.link/5" + } +] diff --git a/tests/routes/qualifications.spec.js b/tests/routes/qualifications.spec.js new file mode 100644 index 00000000..6ccbb5c7 --- /dev/null +++ b/tests/routes/qualifications.spec.js @@ -0,0 +1,33 @@ +import {QualificationMock} from "../../src/models/index.js"; +import chai from 'chai'; +import chaiHttp from 'chai-http'; +import app from '../../src/server.js'; + +// Configure chai +chai.use(chaiHttp); +chai.should(); + +describe("Qualifications Routes", () => { + describe("GET /v1/qualifications/", () => { + it("should get all qualifications", (done) => { + chai.request(app) + .get('/v1/qualifications/?useMock=true') + .end((err, res) => { + res.should.have.status(200); + res.body.should.be.a('array'); + done(); + }); + }); + }); + describe("GET /v1/qualifications/?id=1", () => { + it("should get a single qualification", (done) => { + chai.request(app) + .get('/v1/qualifications/?useMock=true&id=1') + .end((err, res) => { + res.should.have.status(200); + res.body.should.be.a('object'); + done(); + }); + }); + }); +});