CREATE OR REPLACE FUNCTION public.cartridges_insert()
RETURNS trigger
LANGUAGE plpgsql
AS $function$
BEGIN
IF NEW.balance = 0 and NEW.quantity != 0 THEN
NEW.balance := NEW.quantity;
END IF;
NEW.code := (WITH RECURSIVE serialNumber AS (
SELECT
LPAD((RANDOM() * 1e9)::bigint::character(9), 9, '0') AS code,
0 AS nested
UNION ALL
SELECT
LPAD((RANDOM() * 1e9)::bigint::character(9), 9, '0') AS code,
nested + 1 AS nested
FROM serialNumber where nested < 1e6
)
SELECT code FROM serialNumber
WHERE NOT EXISTS (
SELECT FROM "Cartridges" WHERE code = serialNumber.code
)
LIMIT 1
);
RETURN NEW;
END;
$function$
;
user@G500:/etc$ firejail --private=/home/user/viber1 Viber
Reading profile /etc/firejail/Viber.profile
Reading profile /etc/firejail/disable-common.inc
Reading profile /etc/firejail/disable-devel.inc
Reading profile /etc/firejail/disable-interpreters.inc
Reading profile /etc/firejail/disable-passwdmgr.inc
Reading profile /etc/firejail/disable-programs.inc
Reading profile /etc/firejail/whitelist-common.inc
Warning: networking feature is disabled in Firejail configuration file
Parent pid 5210, child pid 5211
Warning: skipping proxychains.conf for private /etc
Warning: skipping crypto-policies for private /etc
Warning: skipping asound.conf for private /etc
Private /etc installed in 94.14 ms
6 programs installed in 20.97 ms
Child process initialized in 254.11 ms
Error: no suitable Viber executable found
Parent is shutting down, bye...
user@G500:/etc$ Viber
Command 'Viber' not found, did you mean:
command 'biber' from deb biber (2.12-2)
Try: sudo apt install <deb name>
const insertDB = async (req, next) => {
const { num, visible, name } = req.body;
if (!name) next(new Error('MISSING_PARAMS'));
const category = await models.GalleryCategory.create({ num, visible, name });
req.categoryId = category.id;
};
const fileFilterCreateCategory = async (req, file, next) => {
if (!allowedTypes.includes(file.mimetype)) {
return next(new Error('LIMIT_FILE_TYPES'));
}
await insertDB(req, next);
return next(null, true);
};
const storageCreateCategory = multer.diskStorage({
destination: (req, file, cb) => cb(null, pathGalleryCategories),
filename: (req, file, cb) => cb(null, req.categoryId.toString())
});
const uploadCreateCategory = multer({
fileFilter: fileFilterCreateCategory,
limits: { fileSize: process.env.APP_MAX_FILE_SIZE },
storage: storageCreateCategory
});
routes.post(
'',
uploadCreateCategory.single('file'),
async (req, res, next) => {
if (!req.file) await insertDB(req, next);
next();
},
(req, res) => res.json({ id: req.categoryId })
);
const fileFilterCreateCategory = async (req, file, next) => {
if (!allowedTypes.includes(file.mimetype)) {
return next(new Error('LIMIT_FILE_TYPES'));
}
return next(null, true);
};
const storageCreateCategory = multer.diskStorage({
destination: (req, file, cb) => cb(null, pathGalleryCategories),
filename: (req, file, cb) => cb(null, req.categoryId.toString())
});
const uploadCreateCategory = multer({
fileFilter: fileFilterCreateCategory,
limits: { fileSize: process.env.APP_MAX_FILE_SIZE },
storage: storageCreateCategory
});
routes.post('',
async (req, res, next) => {
const { num, visible, name } = req.body;
if (!(num && visible && name)) next(new Error('MISSING_PARAMS'));
const category = await models.GalleryCategory.create({ num, visible, name });
req.categoryId = category.id;
next(req.file ? null : new Error('NO_FILE'));
},
uploadCreateCategory.single('file'),
(req, res) => res.json({ id: req.categoryId }));
Я так понял возвращаются только поля которые участвуют в ставке.
А как вернуть все поля таблицы?