1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-20 20:19:35 +02:00

Add app categories (#0)

add app categories
This commit is contained in:
François Darveau 2021-06-26 15:06:47 -04:00 committed by François Darveau
parent 6f44200a3c
commit 31cf2bc5ad
24 changed files with 1772 additions and 939 deletions

View file

@ -42,12 +42,16 @@ exports.getCategories = asyncWrapper(async (req, res, next) => {
where: { key: 'useOrdering' },
});
const orderType = useOrdering ? useOrdering.value : 'createdAt';
const orderType = useOrdering ? useOrdering.value : "createdAt";
let categories;
if (orderType == 'name') {
if (orderType == "name") {
categories = await Category.findAll({
include: [
{
model: App,
as: 'apps',
},
{
model: Bookmark,
as: 'bookmarks',
@ -58,6 +62,10 @@ exports.getCategories = asyncWrapper(async (req, res, next) => {
} else {
categories = await Category.findAll({
include: [
{
model: App,
as: 'apps',
},
{
model: Bookmark,
as: 'bookmarks',
@ -80,6 +88,10 @@ exports.getCategory = asyncWrapper(async (req, res, next) => {
const category = await Category.findOne({
where: { id: req.params.id },
include: [
{
model: App,
as: 'apps',
},
{
model: Bookmark,
as: 'bookmarks',
@ -134,6 +146,10 @@ exports.deleteCategory = asyncWrapper(async (req, res, next) => {
const category = await Category.findOne({
where: { id: req.params.id },
include: [
{
model: App,
as: 'apps',
},
{
model: Bookmark,
as: 'bookmarks',
@ -150,6 +166,12 @@ exports.deleteCategory = asyncWrapper(async (req, res, next) => {
);
}
category.apps.forEach(async (app) => {
await App.destroy({
where: { id: app.id },
});
});
category.bookmarks.forEach(async (bookmark) => {
await Bookmark.destroy({
where: { id: bookmark.id },