mirror of
https://github.com/sergeyyarkov/node-docker-example.git
synced 2026-10-11 02:09:22 +03:00
fix: gen random id for article
This commit is contained in:
parent
95b32bf672
commit
dc89a9eb00
@ -1,4 +1,5 @@
|
|||||||
import db from '#app/db';
|
import db from '#app/db';
|
||||||
|
import crypto from 'node:crypto';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ArticleModel typedef
|
* ArticleModel typedef
|
||||||
@ -57,13 +58,14 @@ class ArticleModel {
|
|||||||
try {
|
try {
|
||||||
const count = await db.client.query('SELECT COUNT(*) FROM "articles"');
|
const count = await db.client.query('SELECT COUNT(*) FROM "articles"');
|
||||||
const values = Object.values({
|
const values = Object.values({
|
||||||
id: String(parseInt(count.rows[0].count, 10) + 1),
|
id: String(parseInt(count.rows[0].count, 10) + crypto.randomInt(100)),
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
body: data.body,
|
body: data.body,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await db.client.query(
|
const result = await db.client.query(
|
||||||
`INSERT INTO "articles" ("id", "title", "description", "body", "created_at", "updated_at") VALUES($1, $2, $3, $4, $5, $6) RETURNING *`,
|
`INSERT INTO "articles" ("id", "title", "description", "body", "created_at", "updated_at") VALUES($1, $2, $3, $4, $5, $6) RETURNING *`,
|
||||||
values
|
values
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@ -7,7 +7,7 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "node-docker-example",
|
"name": "node-docker-example",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.7",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user