|
@ -40,7 +40,7 @@ export class OrderService { |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly prismaService: PrismaService, |
|
|
private readonly prismaService: PrismaService, |
|
|
private readonly symbolProfileService: SymbolProfileService |
|
|
private readonly symbolProfileService: SymbolProfileService |
|
|
) {} |
|
|
) { } |
|
|
|
|
|
|
|
|
public async createOrder( |
|
|
public async createOrder( |
|
|
data: Prisma.OrderCreateInput & { |
|
|
data: Prisma.OrderCreateInput & { |
|
@ -194,77 +194,26 @@ export class OrderService { |
|
|
return order; |
|
|
return order; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async deleteOrders(where: Prisma.OrderWhereInput, filters: Filter[]): Promise<number> { |
|
|
public async deleteOrders({ filters, where }: { filters?: Filter[], where: Prisma.OrderWhereInput }): Promise<number> { |
|
|
|
|
|
const userId = where.userId as string; |
|
|
const { |
|
|
const userCurrency = where.currency as string; |
|
|
ACCOUNT: filtersByAccount, |
|
|
const { activities } = await this.getOrders({ filters, userId, userCurrency }); |
|
|
ASSET_CLASS: filtersByAssetClass, |
|
|
const orderIds = activities.map(order => order.id); |
|
|
TAG: filtersByTag |
|
|
|
|
|
} = groupBy(filters, (filter) => { |
|
|
|
|
|
return filter.type; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (filtersByAccount?.length > 0) { |
|
|
|
|
|
where.accountId = { |
|
|
|
|
|
in: filtersByAccount.map(({ id }) => { |
|
|
|
|
|
return id; |
|
|
|
|
|
}) |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (filtersByAssetClass?.length > 0) { |
|
|
|
|
|
where.SymbolProfile = { |
|
|
|
|
|
OR: [ |
|
|
|
|
|
{ |
|
|
|
|
|
AND: [ |
|
|
|
|
|
{ |
|
|
|
|
|
OR: filtersByAssetClass.map(({ id }) => { |
|
|
|
|
|
return { assetClass: AssetClass[id] }; |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
OR: [ |
|
|
|
|
|
{ SymbolProfileOverrides: { is: null } }, |
|
|
|
|
|
{ SymbolProfileOverrides: { assetClass: null } } |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
SymbolProfileOverrides: { |
|
|
|
|
|
OR: filtersByAssetClass.map(({ id }) => { |
|
|
|
|
|
return { assetClass: AssetClass[id] }; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (filtersByTag?.length > 0) { |
|
|
|
|
|
where.tags = { |
|
|
|
|
|
some: { |
|
|
|
|
|
OR: filtersByTag.map(({ id }) => { |
|
|
|
|
|
return { id }; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { count } = await this.prismaService.order.deleteMany({ |
|
|
const { count } = await this.prismaService.order.deleteMany({ |
|
|
where |
|
|
where: { |
|
|
|
|
|
id: { in: orderIds } |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.eventEmitter.emit( |
|
|
this.eventEmitter.emit( |
|
|
PortfolioChangedEvent.getName(), |
|
|
PortfolioChangedEvent.getName(), |
|
|
new PortfolioChangedEvent({ |
|
|
new PortfolioChangedEvent({ userId: where.userId as string }) |
|
|
userId: <string>where.userId |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
return count; |
|
|
return count; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async getLatestOrder({ dataSource, symbol }: UniqueAsset) { |
|
|
public async getLatestOrder({ dataSource, symbol }: UniqueAsset) { |
|
|
return this.prismaService.order.findFirst({ |
|
|
return this.prismaService.order.findFirst({ |
|
|
orderBy: { |
|
|
orderBy: { |
|
|