pull/1/head
Aji Kamaludin 3 years ago
parent 2fd0f7cf6b
commit 628831e9b5
No known key found for this signature in database
GPG Key ID: 670E1F26AD5A8099

@ -24,7 +24,7 @@ class ProductsService {
name, description, price, cost, stock
FROM products
LEFT JOIN stocks ON stocks.product_id = products.id
WHERE company_id = $1 AND created_at BETWEEN $2 AND $3`,
WHERE company_id = $1 AND products.created_at BETWEEN $2 AND $3`,
values: [companyId, startDate, endDate],
};
}
@ -82,14 +82,18 @@ class ProductsService {
values: [stockId, productId, stock, companyId],
};
const client = await this._pool.connect();
try {
await this._pool.query('BEGIN');
await this._pool.query(productQuery);
await this._pool.query(stockQuery);
await this._pool.query('COMMIT');
await client.query('BEGIN');
await client.query(productQuery);
await client.query(stockQuery);
await client.query('COMMIT');
} catch (err) {
await this._pool.query('ROLLBACK');
throw new InvariantError('Product gagal ditambahkan');
await client.query('ROLLBACK');
throw new InvariantError(`Product gagal ditambahkan: ${err.message}`);
} finally {
client.release();
}
return productId;

@ -97,7 +97,7 @@ class UsersService {
const query = {
text: `SELECT
users.name, users.email, offices.id as officeId, companies.id as companyId
users.name, role, users.email, offices.id as officeId, companies.id as companyId
FROM users
LEFT JOIN companies ON companies.id = users.company_id
LEFT JOIN offices ON companies.id = offices.company_id

Loading…
Cancel
Save