Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 1.3.5 #260

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/controllers/versionController.js
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

View workflow job for this annotation

GitHub Actions / devlop_CICD (16.13.2)

'SuccessMessage' is assigned a value but never used

Check warning on line 5 in src/controllers/versionController.js

View workflow job for this annotation

GitHub Actions / PR_Check (16.13.2)

'SuccessMessage' is assigned a value but never used
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);
}
},
};
48 changes: 48 additions & 0 deletions src/models/version.js
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, []);
},
};
1 change: 1 addition & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const router = new express.Router();

router.get('/', (req, res) => res.send('Welcome to WishBoard!!'));

router.use('/version', require('./versionRoutes'));
router.use('/auth', require('./authRoutes'));
router.use('/user', require('./userRoutes'));
router.use('/item', require('./itemRoutes'));
Expand Down
9 changes: 9 additions & 0 deletions src/routes/versionRoutes.js
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;
4 changes: 4 additions & 0 deletions src/utils/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ const ErrorMessage = {
failedCreateToken: 'token 생성 실패',
userIdNotFound: '토큰을 생성하기 위한 userId data 없음',

/* 버전 */
versionInfoNotFound: '버전 정보 없음',
versionUpdatedFailed: '버전 정보 수정 실패',

/* 공통*/
BadRequestMeg: '잘못된 요청',
ApiUrlIsInvalid: '잘못된 경로',
Expand Down
Loading