-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from AndreySurzhan/develop
Release 07/11/2020
- Loading branch information
Showing
14 changed files
with
322 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const LanguageRepo = require('../repositories/language'); | ||
|
||
|
||
module.exports = class LanguageController { | ||
constructor() { | ||
this.languageRepo = new LanguageRepo(); | ||
} | ||
|
||
async findAllLanguages(req, res, next) { | ||
try { | ||
const languages = await this.languageRepo.findAll(); | ||
|
||
await res.json(languages); | ||
} catch (error) { | ||
next(error); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/// Libs | ||
const mongoose = require('mongoose'); | ||
/// Models | ||
const User = require('./user'); | ||
/// Local variables | ||
const Schema = mongoose.Schema; | ||
|
||
let Language; | ||
|
||
/** | ||
* @swagger | ||
* | ||
* components: | ||
* schemas: | ||
* Language: | ||
* allOf: | ||
* - $ref: '#/components/schemas/MongoId' | ||
* - type: object | ||
* properties: | ||
* code: | ||
* type: string | ||
* name: | ||
* type: string | ||
* - $ref: '#/components/schemas/Audit' | ||
* required: | ||
* - name | ||
* - code | ||
*/ | ||
|
||
/** | ||
* Language mongoose schema. | ||
* @class models/LanguageSchema | ||
*/ | ||
const LanguageSchema = new Schema({ | ||
/** | ||
* The item text. | ||
* | ||
* @type String | ||
* @memberof models/LanguageSchema | ||
*/ | ||
code: { | ||
type: String, | ||
required: true | ||
}, | ||
|
||
/** | ||
* The item text. | ||
* | ||
* @type String | ||
* @memberof models/LanguageSchema | ||
*/ | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
|
||
/** | ||
* The creation date. | ||
* | ||
* @type Date | ||
* @memberof models/LanguageSchema | ||
*/ | ||
created: { | ||
type: Date | ||
}, | ||
|
||
/** | ||
* The date of the last user modification. | ||
* | ||
* @type Date | ||
* @memberof models/LanguageSchema | ||
*/ | ||
modified: { | ||
type: Date, | ||
default: Date.now | ||
}, | ||
|
||
/** | ||
* @type ObjectId | ||
* @memberof models/LanguageSchema | ||
*/ | ||
createdBy: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User' | ||
}, | ||
|
||
/** | ||
* @type ObjectId | ||
* @memberof models/LanguageSchema | ||
*/ | ||
modifiedBy: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'User' | ||
} | ||
}); | ||
|
||
if (mongoose.models.Language) { | ||
Language = mongoose.model('Language'); | ||
} else { | ||
Language = mongoose.model('Language', LanguageSchema); | ||
} | ||
|
||
module.exports = Language; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const logging = require('../utils/logging'); | ||
const LanguageModel = require('../models/language'); | ||
const Repository = require('./repository'); | ||
const NotFoundError = require('../utils/errors').NotFoundError | ||
|
||
module.exports = class LanguageRepository extends Repository { | ||
constructor(){ | ||
super(LanguageModel); | ||
} | ||
|
||
/** | ||
* Method that gets all language models | ||
* | ||
* @async | ||
* @returns {Promise <Query>[]} | ||
* @memberof LanguageRepository | ||
*/ | ||
async findAll() { | ||
let languages = null | ||
|
||
try { | ||
languages = await LanguageModel.find(); | ||
} catch (error) { | ||
logging.error('Failed to find all languages from database'); | ||
|
||
throw error; | ||
} | ||
|
||
if (!languages) { | ||
throw new NotFoundError('Languages don\'t exist') | ||
} | ||
|
||
logging.info('All languages have been successfully found'); | ||
return languages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.