Skip to content

Commit

Permalink
♻️ Prisma refactor update
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jun 24, 2024
1 parent edfd049 commit 564e794
Show file tree
Hide file tree
Showing 211 changed files with 660 additions and 1,458 deletions.
3 changes: 2 additions & 1 deletion packages/api/src/@core/connections/@utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PrismaService } from '@@core/prisma/prisma.service';
import { ConnectionsError, throwTypedError } from '@@core/utils/errors';
import { Injectable } from '@nestjs/common';
import { v4 as uuidv4 } from 'uuid';

export type ConnectionMetadata = {
linkedUserId: string;
remoteSource: string;
connectionId: string;
};

@Injectable()
Expand All @@ -26,6 +26,7 @@ export class ConnectionUtils {
return {
linkedUserId: res.id_linked_user,
remoteSource: res.provider_slug,
connectionId: res.id_connection,
};
} catch (error) {
throw error;
Expand Down
24 changes: 18 additions & 6 deletions packages/api/src/@core/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,19 @@ export class CoreSyncService {
),
);

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: provider.toLowerCase(),
},
});

// Execute all tasks and handle results
const results = await Promise.allSettled(tasks.map((task) => task()));

const deals = await this.prisma.crm_deals.findMany({
where: {
remote_platform: provider,
id_linked_user: linkedUserId,
id_connection: connection.id_connection,
},
});

Expand Down Expand Up @@ -205,12 +211,18 @@ export class CoreSyncService {
),
];

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: provider.toLowerCase(),
},
});

const results = await Promise.allSettled(tasks.map((task) => task()));

const accounts = await this.prisma.tcg_accounts.findMany({
where: {
remote_platform: provider,
id_linked_user: linkedUserId,
id_connection: connection.id_connection,
},
});
let contactTasks = [];
Expand All @@ -233,12 +245,12 @@ export class CoreSyncService {
),
];
}

const contactTasksResults = await Promise.allSettled(contactTasks);

const tickets = await this.prisma.tcg_tickets.findMany({
where: {
remote_platform: provider,
id_linked_user: linkedUserId,
id_connection: connection.id_connection,
},
});

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/accounting/account/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class AccountController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.accountService.getAccounts(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class AccountService {
}

async getAccounts(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/accounting/address/address.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class AddressController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.addressService.getAddresss(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class AddressService {
}

async getAddresss(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class AttachmentController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.attachmentService.getAttachments(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down Expand Up @@ -130,12 +131,13 @@ export class AttachmentController {
@Query('remote_data') remote_data?: boolean,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
return this.attachmentService.addAttachment(
unifiedAttachmentData,
connectionId,
remoteSource,
linkedUserId,
remote_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class AttachmentService {

async addAttachment(
unifiedAttachmentData: UnifiedAttachmentInput,
connection_id: string,
integrationId: string,
linkedUserId: string,
remote_data?: boolean,
Expand All @@ -44,6 +45,7 @@ export class AttachmentService {
}

async getAttachments(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class BalanceSheetController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.balancesheetService.getBalanceSheets(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class BalanceSheetService {
}

async getBalanceSheets(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class CashflowStatementController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.cashflowstatementService.getCashflowStatements(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class CashflowStatementService {
}

async getCashflowStatements(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class CompanyInfoController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.companyinfoService.getCompanyInfos(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class CompanyInfoService {
}

async getCompanyInfos(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/accounting/contact/contact.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class ContactController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.contactService.getContacts(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down Expand Up @@ -130,12 +131,13 @@ export class ContactController {
@Query('remote_data') remote_data?: boolean,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
return this.contactService.addContact(
unifiedContactData,
connectionId,
remoteSource,
linkedUserId,
remote_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ContactService {

async addContact(
unifiedContactData: UnifiedContactInput,
connection_id: string,
integrationId: string,
linkedUserId: string,
remote_data?: boolean,
Expand All @@ -45,6 +46,7 @@ export class ContactService {
}

async getContacts(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class CreditNoteController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.creditnoteService.getCreditNotes(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class CreditNoteService {
}

async getCreditNotes(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/accounting/expense/expense.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class ExpenseController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.expenseService.getExpenses(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down Expand Up @@ -130,12 +131,13 @@ export class ExpenseController {
@Query('remote_data') remote_data?: boolean,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
return this.expenseService.addExpense(
unifiedExpenseData,
connectionId,
remoteSource,
linkedUserId,
remote_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ExpenseService {

async addExpense(
unifiedExpenseData: UnifiedExpenseInput,
connection_id: string,
integrationId: string,
linkedUserId: string,
remote_data?: boolean,
Expand All @@ -45,6 +46,7 @@ export class ExpenseService {
}

async getExpenses(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class IncomeStatementController {
@Query() query: FetchObjectsQueryDto,
) {
try {
const { linkedUserId, remoteSource } =
const { linkedUserId, remoteSource, connectionId } =
await this.connectionUtils.getConnectionMetadataFromConnectionToken(
connection_token,
);
const { remote_data, limit, cursor } = query;
return this.incomestatementService.getIncomeStatements(
connectionId,
remoteSource,
linkedUserId,
limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class IncomeStatementService {
}

async getIncomeStatements(
connectionId: string,
integrationId: string,
linkedUserId: string,
limit: number,
Expand Down
Loading

0 comments on commit 564e794

Please sign in to comment.