feat: wip migrate to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-26 15:40:29 +02:00
parent a6932d76f3
commit cd84872a61
96 changed files with 2051 additions and 745 deletions

View File

@@ -1,7 +1,7 @@
import * as R from 'ramda';
import { Inject, Injectable } from '@nestjs/common';
import { omit, sumBy } from 'lodash';
import composeAsync from 'async/compose';
import * as composeAsync from 'async/compose';
import {
IPaymentReceivedCreateDTO,
IPaymentReceivedEditDTO,
@@ -78,6 +78,6 @@ export class PaymentReceiveDTOTransformer {
return R.compose(
this.branchDTOTransform.transformDTO<PaymentReceived>
)(initialAsyncDTO);
)(initialAsyncDTO) as PaymentReceived;
}
}

View File

@@ -6,6 +6,7 @@ import { Model, mixin } from 'objection';
// import { DEFAULT_VIEWS } from '@/services/Sales/PaymentReceived/constants';
// import ModelSearchable from './ModelSearchable';
import { BaseModel } from '@/models/Model';
import { PaymentReceivedEntry } from './PaymentReceivedEntry';
export class PaymentReceived extends BaseModel {
customerId: number;
@@ -25,6 +26,8 @@ export class PaymentReceived extends BaseModel {
createdAt: string;
updatedAt: string;
entries?: PaymentReceivedEntry[];
/**
* Table name.
*/
@@ -65,17 +68,17 @@ export class PaymentReceived extends BaseModel {
* Relationship mapping.
*/
static get relationMappings() {
const PaymentReceiveEntry = require('models/PaymentReceiveEntry');
const AccountTransaction = require('models/AccountTransaction');
const Customer = require('models/Customer');
const Account = require('models/Account');
const Branch = require('models/Branch');
const Document = require('models/Document');
const { PaymentReceivedEntry } = require('./PaymentReceivedEntry');
const { AccountTransaction } = require('../../Accounts/models/AccountTransaction.model');
const { Customer } = require('../../Customers/models/Customer');
const { Account } = require('../../Accounts/models/Account.model');
const { Branch } = require('../../Branches/models/Branch.model');
// const Document = require('../../Documents/models/Document');
return {
customer: {
relation: Model.BelongsToOneRelation,
modelClass: Customer.default,
modelClass: Customer,
join: {
from: 'payment_receives.customerId',
to: 'contacts.id',
@@ -84,17 +87,19 @@ export class PaymentReceived extends BaseModel {
query.where('contact_service', 'customer');
},
},
depositAccount: {
relation: Model.BelongsToOneRelation,
modelClass: Account.default,
modelClass: Account,
join: {
from: 'payment_receives.depositAccountId',
to: 'accounts.id',
},
},
entries: {
relation: Model.HasManyRelation,
modelClass: PaymentReceiveEntry.default,
modelClass: PaymentReceivedEntry,
join: {
from: 'payment_receives.id',
to: 'payment_receives_entries.paymentReceiveId',
@@ -103,9 +108,10 @@ export class PaymentReceived extends BaseModel {
query.orderBy('index', 'ASC');
},
},
transactions: {
relation: Model.HasManyRelation,
modelClass: AccountTransaction.default,
modelClass: AccountTransaction,
join: {
from: 'payment_receives.id',
to: 'accounts_transactions.referenceId',
@@ -120,7 +126,7 @@ export class PaymentReceived extends BaseModel {
*/
branch: {
relation: Model.BelongsToOneRelation,
modelClass: Branch.default,
modelClass: Branch,
join: {
from: 'payment_receives.branchId',
to: 'branches.id',
@@ -130,21 +136,21 @@ export class PaymentReceived extends BaseModel {
/**
* Payment transaction may has many attached attachments.
*/
attachments: {
relation: Model.ManyToManyRelation,
modelClass: Document.default,
join: {
from: 'payment_receives.id',
through: {
from: 'document_links.modelId',
to: 'document_links.documentId',
},
to: 'documents.id',
},
filter(query) {
query.where('model_ref', 'PaymentReceive');
},
},
// attachments: {
// relation: Model.ManyToManyRelation,
// modelClass: Document.default,
// join: {
// from: 'payment_receives.id',
// through: {
// from: 'document_links.modelId',
// to: 'document_links.documentId',
// },
// to: 'documents.id',
// },
// filter(query) {
// query.where('model_ref', 'PaymentReceive');
// },
// },
};
}

View File

@@ -1,10 +1,14 @@
import { BaseModel } from '@/models/Model';
import { Model, mixin } from 'objection';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { Model } from 'objection';
export class PaymentReceivedEntry extends BaseModel {
paymentReceiveId: number;
invoiceId: number;
paymentAmount: number;
index: number;
invoice?: SaleInvoice;
/**
* Table name
@@ -24,15 +28,15 @@ export class PaymentReceivedEntry extends BaseModel {
* Relationship mapping.
*/
static get relationMappings() {
const PaymentReceive = require('models/PaymentReceive');
const SaleInvoice = require('models/SaleInvoice');
const { PaymentReceived } = require('./PaymentReceived');
const { SaleInvoice } = require('../../SaleInvoices/models/SaleInvoice');
return {
/**
*/
payment: {
relation: Model.BelongsToOneRelation,
modelClass: PaymentReceive.default,
modelClass: PaymentReceived,
join: {
from: 'payment_receives_entries.paymentReceiveId',
to: 'payment_receives.id',
@@ -44,7 +48,7 @@ export class PaymentReceivedEntry extends BaseModel {
*/
invoice: {
relation: Model.BelongsToOneRelation,
modelClass: SaleInvoice.default,
modelClass: SaleInvoice,
join: {
from: 'payment_receives_entries.invoiceId',
to: 'sales_invoices.id',

View File

@@ -1,8 +1,7 @@
import { Inject, Service } from 'typedi';
import { Inject, Injectable } from '@nestjs/common';
import { omit } from 'lodash';
import { IPaymentReceivePageEntry } from '../types/PaymentReceived.types';
import { ERRORS } from '../constants';
import { Injectable } from '@nestjs/common';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { PaymentReceived } from '../models/PaymentReceived';
import { ServiceError } from '@/modules/Items/ServiceError';

View File

@@ -1,3 +1,4 @@
// @ts-nocheck
import { PaymentReceived } from './models/PaymentReceived';
import {
PaymentReceivedPdfTemplateAttributes,