new version using better built-in api for create 6
This commit is contained in:
parent
ac492b1301
commit
634d060c75
1504
package-lock.json
generated
1504
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -15,8 +15,6 @@
|
|||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
"mariadb": "^3.4.5",
|
"mariadb": "^3.4.5",
|
||||||
"sqlight": "^1.0.0-alpha.8",
|
|
||||||
"sqlite3": "^5.1.7",
|
|
||||||
"ws": "^8.18.3"
|
"ws": "^8.18.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
users-api.js
32
users-api.js
@ -380,16 +380,14 @@ module.exports = function (app, wss, pool) {
|
|||||||
if (!userRow)
|
if (!userRow)
|
||||||
return res.status(404).json({ ok: false, error: "User not found" });
|
return res.status(404).json({ ok: false, error: "User not found" });
|
||||||
if (userRow.balance < price * item.quantity)
|
if (userRow.balance < price * item.quantity)
|
||||||
return res
|
return res.status(400).json({
|
||||||
.status(400)
|
ok: false,
|
||||||
.json({
|
error: `Insufficient balance for item ${item.id}`,
|
||||||
ok: false,
|
});
|
||||||
error: `Insufficient balance for item ${item.id}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
const shopId = response.data.shopId;
|
const shopId = response.data.shopId;
|
||||||
if (!shopList[shopId]) shopList[shopId] = [];
|
if (!shopList[shopId]) shopList[shopId] = [];
|
||||||
shopList[shopId].push({ id: item.id, count: item.quantity });
|
shopList[shopId].push({ name: item.id, _requestCount: item.quantity });
|
||||||
total += price * item.quantity;
|
total += price * item.quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,12 +416,10 @@ module.exports = function (app, wss, pool) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await conn.commit();
|
await conn.commit();
|
||||||
res
|
res.status(200).json({
|
||||||
.status(200)
|
ok: true,
|
||||||
.json({
|
message: `Successfully purchased items for user ${userId} at ${total}`,
|
||||||
ok: true,
|
});
|
||||||
message: `Successfully purchased items for user ${userId} at ${total}`,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await conn.rollback();
|
await conn.rollback();
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -462,12 +458,10 @@ module.exports = function (app, wss, pool) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await conn.commit();
|
await conn.commit();
|
||||||
res
|
res.status(200).json({
|
||||||
.status(200)
|
ok: true,
|
||||||
.json({
|
message: `Successfully transferred ${amount} from ${from} to ${to}`,
|
||||||
ok: true,
|
});
|
||||||
message: `Successfully transferred ${amount} from ${from} to ${to}`,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await conn.rollback();
|
await conn.rollback();
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user