feat: enhance business activities and sale invoices handling with new query constants and pagination support
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export enum GoldKarat {
|
||||
KARAT_18 = '18',
|
||||
KARAT_21 = '21',
|
||||
KARAT_24 = '24',
|
||||
KARAT_18 = 'KARAT_18',
|
||||
KARAT_21 = 'KARAT_21',
|
||||
KARAT_24 = 'KARAT_24',
|
||||
}
|
||||
|
||||
export enum TspProviderRequestType {
|
||||
@@ -16,16 +16,16 @@ export enum SKUGuildType {
|
||||
}
|
||||
|
||||
export const UploadedFileTypes = {
|
||||
GOOD: 'good',
|
||||
SERVICE: 'service',
|
||||
PROFILE_AVATAR: 'profile_avatar',
|
||||
PARTNER_LOGO: 'partner_logo',
|
||||
GOOD: 'GOOD',
|
||||
SERVICE: 'SERVICE',
|
||||
PROFILE_AVATAR: 'PROFILE_AVATAR',
|
||||
PARTNER_LOGO: 'PARTNER_LOGO',
|
||||
}
|
||||
export type UploadedFileTypes = (typeof UploadedFileTypes)[keyof typeof UploadedFileTypes]
|
||||
|
||||
export const TspProviderCustomerType = {
|
||||
UNKNOWN: 'Unknown',
|
||||
KNOWN: 'Known',
|
||||
UNKNOWN: 'UNKNOWN',
|
||||
KNOWN: 'KNOWN',
|
||||
}
|
||||
|
||||
export type TspProviderCustomerType =
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { BusinessActivitySelect } from '@/generated/prisma/models'
|
||||
|
||||
export const summarySelect: BusinessActivitySelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
economic_code: true,
|
||||
created_at: true,
|
||||
fiscal_id: true,
|
||||
invoice_number_sequence: true,
|
||||
partner_token: true,
|
||||
guild: {
|
||||
select: {
|
||||
id: true,
|
||||
code: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
license_activation: {
|
||||
select: {
|
||||
id: true,
|
||||
starts_at: true,
|
||||
expires_at: true,
|
||||
license: {
|
||||
select: {
|
||||
activation: {
|
||||
select: {
|
||||
_count: {
|
||||
select: {
|
||||
account_allocations: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const select: BusinessActivitySelect = {
|
||||
...summarySelect,
|
||||
}
|
||||
|
||||
export const mappedData = (businessActivity: any) => {
|
||||
const { license_activation, ...rest } = businessActivity
|
||||
const { license, ...license_activation_rest } = license_activation
|
||||
const { _count } = license.activation
|
||||
|
||||
return {
|
||||
...rest,
|
||||
license_info: {
|
||||
...license_activation_rest,
|
||||
accounts_limit: _count.account_allocations,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as BUSINESS_ACTIVITIES from './businessActivities'
|
||||
import * as CONSUMER from './consumer'
|
||||
import * as LICENSE_ACTIVATION from './licenseActivation'
|
||||
import * as POS from './pos'
|
||||
@@ -8,4 +9,5 @@ export const QUERY_CONSTANTS = {
|
||||
CONSUMER,
|
||||
LICENSE_ACTIVATION,
|
||||
SALE_INVOICE,
|
||||
BUSINESS_ACTIVITIES,
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { QUERY_CONSTANTS } from '@/common/queryConstants'
|
||||
import { BusinessActivitySelect } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
@@ -7,45 +8,35 @@ export class BusinessActivitiesQueryService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
readonly baseSelect: BusinessActivitySelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
economic_code: true,
|
||||
created_at: true,
|
||||
partner_token: true,
|
||||
fiscal_id: true,
|
||||
guild: {
|
||||
select: {
|
||||
id: true,
|
||||
code: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
...QUERY_CONSTANTS.BUSINESS_ACTIVITIES.summarySelect,
|
||||
}
|
||||
|
||||
findAllByConsumer(consumer_id: string, select: BusinessActivitySelect) {
|
||||
return this.prisma.businessActivity.findMany({
|
||||
async findAllByConsumer(consumer_id: string, select: BusinessActivitySelect) {
|
||||
const businessActivities = await this.prisma.businessActivity.findMany({
|
||||
where: { consumer_id },
|
||||
select,
|
||||
})
|
||||
return businessActivities.map(QUERY_CONSTANTS.BUSINESS_ACTIVITIES.mappedData)
|
||||
}
|
||||
|
||||
findOneByConsumer(
|
||||
async findOneByConsumer(
|
||||
consumer_id: string,
|
||||
id: string,
|
||||
select: BusinessActivitySelect,
|
||||
orThrow = false,
|
||||
) {
|
||||
if (orThrow) {
|
||||
return this.prisma.businessActivity.findUniqueOrThrow({
|
||||
where: { consumer_id, id },
|
||||
select,
|
||||
})
|
||||
}
|
||||
// if (orThrow) {
|
||||
// return await this.prisma.businessActivity.findUniqueOrThrow({
|
||||
// where: { consumer_id, id },
|
||||
// select,
|
||||
// })
|
||||
// }
|
||||
|
||||
return this.prisma.businessActivity.findUnique({
|
||||
const businessActivity = await this.prisma.businessActivity.findUnique({
|
||||
where: { consumer_id, id },
|
||||
select,
|
||||
})
|
||||
|
||||
return QUERY_CONSTANTS.BUSINESS_ACTIVITIES.mappedData(businessActivity)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ export class SharedSaleInvoiceCreateService {
|
||||
const terminalInfo = rawPayments.terminals as TerminalPaymentInfo | undefined
|
||||
|
||||
const payments: NormalizedPayment[] = Object.entries(rawPayments)
|
||||
.filter(([key]) => key !== 'terminals')
|
||||
.filter(([key, value]) => key !== 'terminals' && value && Number(value) > 0)
|
||||
.map(([key, value]) => ({
|
||||
method: paymentMethodMap[key.toLowerCase()],
|
||||
amount: typeof value === 'number' ? value : Number(value || 0),
|
||||
|
||||
@@ -12,6 +12,8 @@ export function translateEnumValue(
|
||||
enumKey: keyof typeof translates.enums,
|
||||
value: string | null | undefined,
|
||||
): EnumTranslatedValue {
|
||||
console.log(enumKey, value)
|
||||
|
||||
const enumsRegistry = translates.enums as EnumsRegistry
|
||||
const enumMap = enumsRegistry[String(enumKey)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user