[Kiwi-ํ๊ณผ์ปค๋ฎค๋ํฐ] ํ์ ํ๊ณผ๋ณ๊ฒฝ API ๊ตฌํ
๐ฅ Project/Kiwi
schema.js
updateDept(id: ID!, departmentId: ID!): Boolean
index.js
updateDept: require('./admin/user/updateDept'),
resolvers/admin/user/updateDept.js
const models = require('../../../../models');
const { ConflictError } = require('../../../errors/errors');
const isAdmin = require('../../../middlewares/isAdmin');
const { createAdminLog } = require('../../../services/log.service');
const { setCachedUserUpdated } = require('../../../../api/caching');
module.exports = async ({ id, departmentId }, { id: userId }) => {
await isAdmin(userId);
return await models.user
.update(
{
departmentId,
},
{ where: { id } },
)
.then(async () => {
createAdminLog(userId, `ํ์ [ID ${id}] ํ๊ณผ [${departmentId}]์ผ๋ก ๋ณ๊ฒฝ`);
await setCachedUserUpdated(id);
return true;
})
.catch(() => {
throw ConflictError('Delete(Update) error occured');
});
};
ํ๋ง๋
Kiwi ํ๋ก์ ํธ์์ ์ ๊ณผ๋ฅผ ํ๋ ์ ์ ์ ํ๊ณผ๋ฅผ ๋ณ๊ฒฝํด์ค์ผ ํ๋ ๊ธฐ๋ฅ์ด ํ์ํ๋ค๊ณ ๋๊ผ๋ค.
์ ์ ๊ฐ ๊ด๋ฆฌ์์๊ฒ ํ๊ณผ ๋ณ๊ฒฝ์ ์์ฒญํ๋ฉด ๊ด๋ฆฌ์๋ ๊ด๋ฆฌ์ํ์ด์ง์์ ํด๋น ์ ์ ์ ํ๊ณผ๋ฅผ ๋ณ๊ฒฝํด์ค ์ ์๋ค.
ํ๊ณผ๋ณ๊ฒฝ API๋ฅผ ๊ตฌํํ๋ ๋ฐ์ ์์ด ์ด๋ ค์ด ๋ถ๋ถ์ ๋ฑํ ์์๋ค.
'๐ฅ Project > Kiwi' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Kiwi-ํ๊ณผ์ปค๋ฎค๋ํฐ] ํ์ํํด API ๊ตฌํ (0) | 2021.05.19 |
---|