last
This commit is contained in:
parent
30411cb43c
commit
d4dfcd12fb
@ -34,13 +34,6 @@ class SectionController {
|
||||
|
||||
getFillteredList = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
// Сюда приходит id текущего товара при редактировании,
|
||||
// чтобы не возвращать его в списке
|
||||
// или же флаг onlyEndSections
|
||||
// const filter: { onlyEndSections: boolean } | { id: number } = req.query.filter
|
||||
// ? JSON.parse(req.query.filter.toString())
|
||||
// : {};
|
||||
|
||||
const currentSectionId: number = req.query.id
|
||||
? JSON.parse(req.query.id.toString())
|
||||
: -1;
|
||||
@ -49,13 +42,6 @@ class SectionController {
|
||||
? JSON.parse(req.query.onlyEndSections.toString())
|
||||
: false;
|
||||
|
||||
// const range: RangeQueryParamType = req.query.range
|
||||
// ? JSON.parse(req.query.range.toString())
|
||||
// : [0, 10];
|
||||
// const sort: SortQueryParamType = req.query.sort
|
||||
// ? JSON.parse(req.query.sort.toString())
|
||||
// : ["id", "ASC"];
|
||||
|
||||
if (onlyEndSections === true) {
|
||||
const endSections = await sequelize.query(
|
||||
`
|
||||
@ -68,22 +54,6 @@ class SectionController {
|
||||
return res.json(endSections);
|
||||
}
|
||||
|
||||
// const sections = await Section.findAndCountAll({
|
||||
// offset: range[0],
|
||||
// limit: range[1] - range[0] + 1,
|
||||
// order: [sort] as Order,
|
||||
// include: {
|
||||
// model: Thread,
|
||||
// required: false,
|
||||
// where: { id: null }
|
||||
// },
|
||||
// where: {
|
||||
// id: {
|
||||
// [Op.ne]: filter && "id" in filter ? filter.id : null
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
const sections = await sequelize.query(
|
||||
`SELECT * FROM sections WHERE id != ${currentSectionId} AND id NOT IN
|
||||
(SELECT DISTINCT section_id FROM threads) AND
|
||||
@ -138,7 +108,7 @@ class SectionController {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const section = await Section.findByPk(id);
|
||||
if (!section) return next(ApiErrorHandler.notFound("Такой роли не найдено"));
|
||||
if (!section) return next(ApiErrorHandler.notFound("Такой секции не найдено"));
|
||||
|
||||
return res.json(section);
|
||||
} catch (error) {
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import Thread from "../../models/thread.model";
|
||||
import { getRandomNumber } from "../../helpers/get-random-number.helper";
|
||||
import type { IThreadDto } from "../../controllers/thread/thread.dto";
|
||||
import { sequelize } from "../../db";
|
||||
|
||||
export async function seedThreads(
|
||||
@ -15,7 +13,7 @@ export async function seedThreads(
|
||||
for (let i = 0; i < length; i++) {
|
||||
let startQueryString = `INSERT INTO threads (name, creator_id, section_id) VALUES `;
|
||||
const name = faker.lorem.words({ min: 3, max: 7 });
|
||||
const creator_id = getRandomNumber(41, 45);
|
||||
const creator_id = getRandomNumber(1, usersLength);
|
||||
const section_id = getRandomNumber(allSectionsLength / 2 + 1, allSectionsLength);
|
||||
startQueryString += `('${name}', ${creator_id}, ${section_id})`;
|
||||
await sequelize.query(`${startQueryString};`);
|
||||
|
Loading…
Reference in New Issue
Block a user