-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const Version = require('../models/version'); | ||
const { BadRequest } = require('../utils/errors'); | ||
const { | ||
StatusCode, | ||
SuccessMessage, | ||
Check warning on line 5 in src/controllers/versionController.js GitHub Actions / devlop_CICD (16.13.2)
|
||
ErrorMessage, | ||
} = require('../utils/response'); | ||
|
||
module.exports = { | ||
checkVersion: async function (req, res, next) { | ||
try { | ||
if (!req.query.osType) { | ||
throw new BadRequest(ErrorMessage.BadRequestMeg); | ||
} | ||
await Version.checkVersion(req).then((result) => { | ||
return res.status(StatusCode.OK).json(result); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
updateVersion: async function (req, res, next) { | ||
try { | ||
if ( | ||
!req.body.osType || | ||
!req.body.minVersion || | ||
!req.body.recommendedVersion | ||
) { | ||
throw new BadRequest(ErrorMessage.BadRequestMeg); | ||
} | ||
await Version.updateVersion(req).then((result) => { | ||
return res.status(StatusCode.OK).json(result); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
getVersions: async function (req, res, next) { | ||
try { | ||
await Version.getVersions(req).then((result) => { | ||
return res.status(StatusCode.OK).json(result); | ||
}); | ||
} catch (err) { | ||
next(err); | ||
} | ||
}, | ||
}; |
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,48 @@ | ||
const db = require('../config/db'); | ||
const { NotFound } = require('../utils/errors'); | ||
const { ErrorMessage } = require('../utils/response'); | ||
|
||
module.exports = { | ||
checkVersion: async function (req) { | ||
const osType = req.query.osType; | ||
|
||
const sqlSelect = | ||
'SELECT min_version, recommended_version FROM deploy WHERE platform = ?'; | ||
const [rows] = await db.query(sqlSelect, osType); | ||
|
||
if (rows.length < 1) { | ||
throw new NotFound(ErrorMessage.versionInfoNotFound); | ||
} | ||
|
||
return { | ||
platform: osType, | ||
minVersion: rows[0].min_version, | ||
recommendedVersion: rows[0].recommended_version, | ||
}; | ||
}, | ||
updateVersion: async function (req) { | ||
const osType = req.body.osType; | ||
const minVersion = req.body.minVersion; | ||
const recommendedVersion = req.body.recommendedVersion; | ||
|
||
const sqlUpdate = | ||
'UPDATE deploy SET min_version = ?, recommended_version = ? WHERE platform = ?'; | ||
const params = [minVersion, recommendedVersion, osType]; | ||
const [updated] = await db.queryWithTransaction(sqlUpdate, params); | ||
|
||
if (updated.affectedRows < 1) { | ||
throw new NotFound(ErrorMessage.versionUpdatedFailed); | ||
} | ||
return true; | ||
}, | ||
getVersions: async function (req) { | ||
const sqlSelect = 'SELECT * FROM deploy'; | ||
const [rows] = await db.query(sqlSelect, null); | ||
|
||
if (rows.length < 1) { | ||
throw new NotFound(ErrorMessage.versionInfoNotFound); | ||
} | ||
|
||
return Object.setPrototypeOf(rows, []); | ||
}, | ||
}; |
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,9 @@ | ||
const versionController = require('../controllers/versionController'); | ||
const express = require('express'); | ||
const router = new express.Router(); | ||
|
||
router.get('/check', versionController.checkVersion); | ||
router.get('/', versionController.getVersions); | ||
router.put('/', versionController.updateVersion); | ||
|
||
module.exports = router; |
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