-
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.
refactor: group by controller category
- ๊ธฐ์กด CROUD์์ ํ ์ด๋ธ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ค๋ ์ปจํธ๋กค๋ฌ๊ฐ ์ถ๊ฐ๋์๊ธฐ ๋๋ฌธ์, ๋ฐ์ดํฐ๋ฅผ ์ฐ๊ณ , ์ฝ๊ณ , ์ญ์ , ์์ ํ๋ ์ปจํธ๋กค๋ฌ์ ๋จ์ํ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ค ๋ ์ปจํธ๋กค๋ฌ๋ฅผ ๋ถ๋ฆฌ (ํ์์๊ฒฌ) - elasitc search๋ ๋น๋๊ธฐ ์ด๋ฒคํธ๊ฐ ์๊ธฐ ๋๋ฌธ์, ์ ์์ ์ผ๋ก ํ ์คํธ๊ฐ ๋์ง ์๊ณ , ์ถํ ์์ ์์ - close #29
- Loading branch information
Showing
16 changed files
with
163 additions
and
172 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
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
Binary file not shown.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
import { getProductSchemaByKey } from '../../core'; | ||
|
||
const getProductSchemaController = (req, res) => { | ||
const list = getProductSchemaByKey('category').enumValues; | ||
res.json(list); | ||
}; | ||
|
||
export default getProductSchemaController; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,77 @@ | ||
import { | ||
removeProduct, | ||
getProducts, | ||
getElasticSearchResults, | ||
updateProduct, | ||
insertProduct, | ||
} from '../../core'; | ||
|
||
export const deleteProductController = async ({ params: { id } }, res, next) => { | ||
try { | ||
const result = await removeProduct(id, res.locals.userId); | ||
res.json(result); | ||
} catch (e) { | ||
next(e); | ||
} | ||
}; | ||
|
||
export const getProductListController = async (req, res, next) => { | ||
if (res.locals.filter) { | ||
res.locals.query = { | ||
bool: { | ||
must: res.locals.filter, | ||
}, | ||
}; | ||
delete res.locals.filter; | ||
} | ||
try { | ||
const list = await getElasticSearchResults(res.locals); | ||
res.json(list); | ||
} catch (e) { | ||
next({ status: 400, message: e.toString() }); | ||
} | ||
}; | ||
|
||
export const findProductByIdController = async ({ params: { id } }, res, next) => { | ||
try { | ||
const result = await getProducts(1, 1, { _id: id }); | ||
res.json(result); | ||
} catch (e) { | ||
next({ status: 400, message: e.toString() }); | ||
} | ||
}; | ||
|
||
export const modifyProductController = async (req, res, next) => { | ||
const { body, params: { id } } = req; | ||
const { locals: { userId } } = res; | ||
try { | ||
const result = await updateProduct(id, userId, body); | ||
res.json(result); | ||
} catch (e) { | ||
next({ status: 400, message: e.toString() }); | ||
} | ||
}; | ||
|
||
export const productListLookupController = async (req, res, next) => { | ||
const { | ||
options = {}, | ||
sort = { order: -1, createAt: 1 }, | ||
page = 1, | ||
limits = 10, | ||
} = res.lcoals; | ||
try { | ||
const result = await getProducts(options, sort, page, limits); | ||
res.json(result); | ||
} catch (e) { | ||
next({ status: 400, message: e.toString() }); | ||
} | ||
}; | ||
|
||
export const writeProductCotroller = async ({ body }, res, next) => { | ||
try { | ||
const result = await insertProduct(body); | ||
res.json(result); | ||
} catch (e) { | ||
next({ status: 400, message: e.toString() }); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import express from 'express'; | ||
import { getProductSchemaByKey } from '../core'; | ||
import getProductSchemaController from './controller/info'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/category', (req, res) => { | ||
const list = getProductSchemaByKey('category').enumValues; | ||
res.json(list); | ||
}); | ||
router.get('/category', getProductSchemaController); | ||
|
||
export default router; |
Oops, something went wrong.