update: add totalItemsCount in get-user-orders response
This commit is contained in:
parent
5aa1da59e1
commit
186e8019cc
3 changed files with 32 additions and 19 deletions
|
|
@ -240,6 +240,8 @@ class OrdersController {
|
||||||
throw new Error('ordersModel.getUserOrders returned Internal error');
|
throw new Error('ordersModel.getUserOrders returned Internal error');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { totalItemsCount } = result;
|
||||||
|
|
||||||
const userOrders = result.data.map((order) => {
|
const userOrders = result.data.map((order) => {
|
||||||
const mappedOrder: GetUserOrdersResOrderData = {
|
const mappedOrder: GetUserOrdersResOrderData = {
|
||||||
id: order.id,
|
id: order.id,
|
||||||
|
|
@ -285,6 +287,7 @@ class OrdersController {
|
||||||
|
|
||||||
res.status(200).send({
|
res.status(200).send({
|
||||||
success: true,
|
success: true,
|
||||||
|
totalItemsCount,
|
||||||
data: userOrders,
|
data: userOrders,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ export type GetUserOrdersResOrderData = {
|
||||||
|
|
||||||
export type GetUserOrdersSuccessRes = {
|
export type GetUserOrdersSuccessRes = {
|
||||||
success: true;
|
success: true;
|
||||||
|
totalItemsCount: number;
|
||||||
data: GetUserOrdersResOrderData[];
|
data: GetUserOrdersResOrderData[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Op } from 'sequelize';
|
import { Op, WhereOptions } from 'sequelize';
|
||||||
import Decimal from 'decimal.js';
|
import Decimal from 'decimal.js';
|
||||||
import TransactionWithOrders from '@/interfaces/common/Transaction.js';
|
import TransactionWithOrders from '@/interfaces/common/Transaction.js';
|
||||||
import Currency from '@/schemes/Currency.js';
|
import Currency from '@/schemes/Currency.js';
|
||||||
|
|
@ -409,6 +409,7 @@ class OrdersModel {
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
success: true;
|
success: true;
|
||||||
|
totalItemsCount: number;
|
||||||
data: {
|
data: {
|
||||||
id: number;
|
id: number;
|
||||||
type: string;
|
type: string;
|
||||||
|
|
@ -436,24 +437,28 @@ class OrdersModel {
|
||||||
|
|
||||||
if (!userRow) throw new Error('Invalid address from token.');
|
if (!userRow) throw new Error('Invalid address from token.');
|
||||||
|
|
||||||
|
const ordersSelectWhereClause: WhereOptions = {
|
||||||
|
user_id: userRow.id,
|
||||||
|
...(status !== undefined
|
||||||
|
? {
|
||||||
|
status:
|
||||||
|
status === 'finished' ? OrderStatus.FINISHED : OrderStatus.ACTIVE,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
...(type !== undefined
|
||||||
|
? { type: type === 'buy' ? OrderType.BUY : OrderType.SELL }
|
||||||
|
: {}),
|
||||||
|
...(date !== undefined
|
||||||
|
? { timestamp: { [Op.between]: [date.from, date.to] } }
|
||||||
|
: {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const totalItemsCount = await Order.count({
|
||||||
|
where: ordersSelectWhereClause,
|
||||||
|
});
|
||||||
|
|
||||||
const ordersRows = (await Order.findAll({
|
const ordersRows = (await Order.findAll({
|
||||||
where: {
|
where: ordersSelectWhereClause,
|
||||||
user_id: userRow.id,
|
|
||||||
...(status !== undefined
|
|
||||||
? {
|
|
||||||
status:
|
|
||||||
status === 'finished'
|
|
||||||
? OrderStatus.FINISHED
|
|
||||||
: OrderStatus.ACTIVE,
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
...(type !== undefined
|
|
||||||
? { type: type === 'buy' ? OrderType.BUY : OrderType.SELL }
|
|
||||||
: {}),
|
|
||||||
...(date !== undefined
|
|
||||||
? { timestamp: { [Op.between]: [date.from, date.to] } }
|
|
||||||
: {}),
|
|
||||||
},
|
|
||||||
order: [['timestamp', 'DESC']],
|
order: [['timestamp', 'DESC']],
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
|
|
@ -487,7 +492,11 @@ class OrdersModel {
|
||||||
isInstant: dexModel.isBotActive(e.id),
|
isInstant: dexModel.isBotActive(e.id),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return { success: true, data: result };
|
return {
|
||||||
|
success: true,
|
||||||
|
totalItemsCount,
|
||||||
|
data: result,
|
||||||
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return { success: false, data: 'Internal error' };
|
return { success: false, data: 'Internal error' };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue