Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 43 additions & 29 deletions packages/plugin-loans-api/src/messageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { generateModels } from './connectionResolver';
import fetch from 'node-fetch';
import { consumeRPCQueue } from '@erxes/api-utils/src/messageBroker';
import { getCloseInfo } from './models/utils/closeUtils';
import { IConfig } from './interfaces/config';
import { dealContract } from './utils';

type CustomFieldType = 'core:customer';
Expand All @@ -15,7 +14,7 @@ export const setupMessageConsumers = async () => {

return {
status: 'success',
data: await models.Contracts.find(data).lean(),
data: await models.Contracts.find(data).lean()
};
});

Expand All @@ -24,7 +23,7 @@ export const setupMessageConsumers = async () => {

return {
status: 'success',
data: await models.Contracts.findOne(data).lean(),
data: await models.Contracts.findOne(data).lean()
};
});

Expand All @@ -35,7 +34,7 @@ export const setupMessageConsumers = async () => {

return {
status: 'success',
data: await models.FirstSchedules.findOne(data).lean(),
data: await models.FirstSchedules.findOne(data).lean()
};
}
);
Expand All @@ -47,7 +46,7 @@ export const setupMessageConsumers = async () => {
const result = await models.Contracts.updateOne(selector, modifier);
return {
status: 'success',
data: result,
data: result
};
});

Expand All @@ -56,12 +55,12 @@ export const setupMessageConsumers = async () => {
async ({ subdomain, data }) => {
const models = await generateModels(subdomain);
const contract = await models.Contracts.getContract({
_id: data.contractId,
_id: data.contractId
});
const closeInfo = await getCloseInfo(models, contract, data.closeDate);
return {
status: 'success',
data: closeInfo,
data: closeInfo
};
}
);
Expand All @@ -73,7 +72,7 @@ export const setupMessageConsumers = async () => {

return {
status: 'success',
data: await dealContract(dealId, args, models, subdomain),
data: await dealContract(dealId, args, models, subdomain)
};
}
);
Expand All @@ -82,15 +81,15 @@ export const setupMessageConsumers = async () => {
const models = await generateModels(subdomain);
return {
status: 'success',
data: await models.ContractTypes.findOne(data).lean(),
data: await models.ContractTypes.findOne(data).lean()
};
});

consumeRPCQueue('loans:purposeType.findOne', async ({ subdomain, data }) => {
const models = await generateModels(subdomain);
return {
status: 'success',
data: await models.LoanPurpose.findOne(data).lean(),
data: await models.LoanPurpose.findOne(data).lean()
};
});

Expand All @@ -100,7 +99,7 @@ export const setupMessageConsumers = async () => {
const models = await generateModels(subdomain);
return {
status: 'success',
data: await models.CollateralTypes.findOne(data).lean(),
data: await models.CollateralTypes.findOne(data).lean()
};
}
);
Expand All @@ -110,7 +109,7 @@ export const setupMessageConsumers = async () => {

return {
status: 'success',
data: await models.ContractTypes.find(data).lean(),
data: await models.ContractTypes.find(data).lean()
};
});

Expand All @@ -119,7 +118,7 @@ export const setupMessageConsumers = async () => {

return {
status: 'success',
data: await models.Transactions.find(data).lean(),
data: await models.Transactions.find(data).lean()
};
});

Expand All @@ -132,14 +131,29 @@ export const setupMessageConsumers = async () => {
return {
status: 'success',
data: await models.Transactions.find({
contractId: { $in: contracts.map((c) => c._id) },
}).lean(),
contractId: { $in: contracts.map((c) => c._id) }
}).lean()
};
}
);

consumeRPCQueue(
'savings:transactions.update',
async ({ subdomain, data }) => {
const models = await generateModels(subdomain);
const { selector, modifier } = data;
const result = await models.Transactions.updateOne(selector, modifier);

return {
status: 'success',
data: result
};
}
);

consumeRPCQueue('loans:transaction', async ({ subdomain, data }) => {
return {
status: 'success',
status: 'success'
};
});
consumeRPCQueue(
Expand All @@ -149,7 +163,7 @@ export const setupMessageConsumers = async () => {

return {
data: await models.FirstSchedules.insertMany(data),
status: 'success',
status: 'success'
};
}
);
Expand All @@ -158,7 +172,7 @@ export const setupMessageConsumers = async () => {

return {
data: await models.FirstSchedules.insertMany(data),
status: 'success',
status: 'success'
};
});
};
Expand All @@ -178,7 +192,7 @@ export const sendMessageBroker = async (
): Promise<any> => {
return sendMessage({
serviceName: name,
...args,
...args
});
};

Expand All @@ -187,7 +201,7 @@ export const sendCoreMessage = async (
): Promise<any> => {
return sendMessage({
serviceName: 'core',
...args,
...args
});
};

Expand All @@ -196,7 +210,7 @@ export const sendSalesMessage = async (
): Promise<any> => {
return sendMessage({
serviceName: 'sales',
...args,
...args
});
};

Expand All @@ -205,15 +219,15 @@ export const sendReactionsMessage = async (
): Promise<any> => {
return sendMessage({
serviceName: 'reactions',
...args,
...args
});
};

export const sendCommonMessage = async (
args: MessageArgs & { serviceName: string }
): Promise<any> => {
return sendMessage({
...args,
...args
});
};

Expand All @@ -229,16 +243,16 @@ export const getFieldObject = async (
data: {
query: {
contentType: customFieldType,
code: { $exists: true, $ne: '' },
code: { $exists: true, $ne: '' }
},
projection: {
groupId: 1,
code: 1,
_id: 1,
},
_id: 1
}
},
isRPC: true,
defaultValue: [],
defaultValue: []
});

return fields.find((row) => row.code === code);
Expand Down Expand Up @@ -266,7 +280,7 @@ export const getConfig = async (
action: 'getConfig',
data: { code, defaultValue },
isRPC: true,
defaultValue,
defaultValue
});
};

Expand Down Expand Up @@ -298,7 +312,7 @@ export const sendSms = async (
key: MESSAGE_PRO_API_KEY,
from: MESSAGE_PRO_PHONE_NUMBER,
to: phoneNumber,
text: content,
text: content
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IBankTransaction {
toOwner?: string;
}

export interface IEBarimt { }
export interface IEBarimt {}

export interface ITransaction {
number?: string;
Expand Down Expand Up @@ -65,6 +65,7 @@ export interface ITransaction {
isOrganization?: boolean;
organizationRegister?: string;
scheduleId?: string;
isSyncedTransaction?: boolean;
}

export interface ITransactionDocument extends ITransaction, Document {
Expand Down Expand Up @@ -211,6 +212,11 @@ export const transactionSchema = schemaHooksWrapper(
type: String,
optional: true,
label: 'scheduleId'
}),
isSyncedTransaction: field({
type: Boolean,
label: 'Is Synced transaction',
optional: true
})
}),
'erxes_transactionSchema'
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-loans-ui/src/transactions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ITransactionDoc {
total: number;
futureDebt?: number;
debtTenor?: number;
isSyncedTransaction?: boolean;
}

export interface ITransaction extends ITransactionDoc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ const contractQueries = {

return {
list: await paginate(
models.Contracts.find(filter).sort(sortBuilder(params)),
models.Contracts.find(filter).sort(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new sort call passes two objects to .sort(). Mongoose expects a single sort object. Merge the sort criteria (e.g., combine { createdAt: -1 } with sortBuilder(params)) to ensure proper sorting.

{ createdAt: -1 },
sortBuilder(params)
),
{
page: params.page,
perPage: params.perPage
Expand Down Expand Up @@ -345,11 +348,11 @@ const contractQueries = {
const account = await models.Contracts.findOne({ number: accountNumber });

if (!account) {
throw new Error('cant find account')
throw new Error('cant find account');
}

if (!account.customerId) {
throw new Error('this account has not customer')
throw new Error('this account has not customer');
}

const customer = await sendMessageBroker(
Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-savings-api/src/messageBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ export const setupMessageConsumers = async () => {
};
}
);

consumeRPCQueue(
"savings:transactions.update",
async ({ subdomain, data }) => {
const models = await generateModels(subdomain);
const { selector, modifier } = data;
const result = await models.Transactions.updateOne(selector, modifier);

return {
status: "success",
data: result
};
}
);
};

export const getConfig = async (
Expand Down
Loading