Skip to content

Commit

Permalink
0.27.1 (#873)
Browse files Browse the repository at this point in the history
Merging the branch next into the branch main
  • Loading branch information
chavda-bhavik authored Nov 18, 2024
2 parents f1f9958 + 34dfecc commit e8d7590
Show file tree
Hide file tree
Showing 115 changed files with 21,459 additions and 18,984 deletions.
4 changes: 2 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@impler/api",
"version": "0.27.0",
"version": "0.27.1",
"author": "implerhq",
"license": "MIT",
"private": true,
Expand Down Expand Up @@ -47,7 +47,7 @@
"class-validator": "^0.14.0",
"compression": "^1.7.4",
"cookie-parser": "^1.4.6",
"cron": "^3.1.7",
"cron": "^3.1.9",
"date-fns": "^2.30.0",
"dayjs": "^1.11.11",
"dotenv": "^16.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ export class ValidRequest {
);
}

const columnKeysSet = new Set(parsedSchema.map((column) => column.key));
const columnKeysSet = new Set();
const duplicateKeys = parsedSchema.reduce((acc, item) => {
if (columnKeysSet.has(item.key)) acc.add(item.key);
columnKeysSet.add(item.key);

return acc;
}, new Set());
if (columnKeysSet.size !== parsedSchema.length) {
throw new UniqueColumnException(APIMessages.COLUMN_KEY_TAKEN);
throw new UniqueColumnException(
`${APIMessages.COLUMN_KEY_DUPLICATED} Duplicate Keys Found for ${[...duplicateKeys].join(', ')}`
);
}

for (const item of parsedSchema) {
Expand Down Expand Up @@ -115,6 +123,16 @@ export class ValidRequest {

return { success: true };
} catch (error) {
if (error instanceof UniqueColumnException) {
throw new HttpException(
{
message: error.message,
errorCode: error.getStatus(),
},
HttpStatus.UNPROCESSABLE_ENTITY
);
}

if (error instanceof DocumentNotFoundException) {
throw new HttpException(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class UpdateUserJob {

private scheduleRssImportJob(jobId: string, cronExpression: string) {
const job = new CronJob(cronExpression, () => this.userJobTriggerService.execute(jobId));
this.schedulerRegistry.addCronJob(this.nameService.getCronName(jobId), job);
this.schedulerRegistry.addCronJob(this.nameService.getCronName(jobId), job as any);

job.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueuesEnum } from '@impler/shared';
export class UserJobTriggerService {
constructor(private readonly queueService: QueueService) {}

async execute(_jobId: string) {
execute(_jobId: string) {
this.queueService.publishToQueue(QueuesEnum.GET_IMPORT_JOB_DATA, { _jobId });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export class UserJobResume {
const existingJob = this.schedulerRegistry.getCronJob(this.nameService.getCronName(_jobId));

if (existingJob) {
existingJob.setTime(new CronTime(cronExpression));
existingJob.setTime(new CronTime(cronExpression) as any);
existingJob.start();
} else {
const newJob = new CronJob(cronExpression, () => this.userJobTriggerService.execute(_jobId));
this.schedulerRegistry.addCronJob(this.nameService.getCronName(_jobId), newJob);

this.schedulerRegistry.addCronJob(this.nameService.getCronName(_jobId), newJob as any);
newJob.start();
}

Expand Down
7 changes: 3 additions & 4 deletions apps/api/src/app/review/review.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { APIMessages } from '@shared/constants';
import { JwtAuthGuard } from '@shared/framework/auth.gaurd';
import { validateUploadStatus } from '@shared/helpers/upload.helpers';
import { Defaults, ACCESS_KEY_NAME, UploadStatusEnum, ReviewDataTypesEnum, IJwtPayload } from '@impler/shared';
import { Defaults, ACCESS_KEY_NAME, UploadStatusEnum, ReviewDataTypesEnum } from '@impler/shared';

import {
Replace,
Expand All @@ -29,7 +29,6 @@ import {
UpdateRecords,
} from './usecases';

import { UserSession } from '@shared/framework/user.decorator';
import { validateNotFound } from '@shared/helpers/common.helper';
import { DeleteRecordsDto, UpdateRecordDto, ReplaceDto } from './dtos';
import { PaginationResponseDto } from '@shared/dtos/pagination-response.dto';
Expand Down Expand Up @@ -124,7 +123,7 @@ export class ReviewController {
@ApiOperation({
summary: 'Confirm review data for uploaded file',
})
async doConfirmReview(@UserSession() user: IJwtPayload, @Param('uploadId', ValidateMongoId) _uploadId: string) {
async doConfirmReview(@Param('uploadId', ValidateMongoId) _uploadId: string) {
const uploadInformation = await this.getUpload.execute({
uploadId: _uploadId,
select: 'status _validDataFileId _invalidDataFileId totalRecords invalidRecords _templateId',
Expand All @@ -136,7 +135,7 @@ export class ReviewController {
// upload files with status reviewing can only be confirmed
validateUploadStatus(uploadInformation.status as UploadStatusEnum, [UploadStatusEnum.REVIEWING]);

return this.startProcess.execute(_uploadId, user.email);
return this.startProcess.execute(_uploadId);
}

@Put(':uploadId/record')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class StartProcess {
private paymentAPIService: PaymentAPIService
) {}

async execute(_uploadId: string, email: string) {
async execute(_uploadId: string) {
let uploadInfo = await this.uploadRepository.getUploadWithTemplate(_uploadId, ['destination']);
let importedData;
const destination = (uploadInfo._templateId as unknown as TemplateEntity)?.destination;
Expand Down Expand Up @@ -72,7 +72,7 @@ export class StartProcess {
uploadedFileId: uploadInfo._uploadedFileId,
});

return { uploadInfo, importedData, email };
return { uploadInfo, importedData };
}

async getImportedData({
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/app/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const APIMessages = {
INVALID_AUTH_TOKEN: 'Invalid authentication token',
INVALID_RSS_URL: 'The Specified URL doesn`t contain any RSS XML Feed, Please enter a Valid RSS XML URL',
COLUMN_KEY_TAKEN: 'Column with the same key already exists. Please provide a unique key from "Validations".',
COLUMN_KEY_DUPLICATED: 'Column with the same key already exists. Please provide a unique key.',
COLUMN_KEY_DUPLICATED: 'Column with the same key already exists. Please use a unique key in column.',
ERROR_DURING_VALIDATION:
'Something went wrong while validating data. Data is not imported yet, but team is informed about issue. Please try again after sometime.',
FEATURE_UNAVAILABLE: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class UpdateTemplateColumns {
{ _templateId },
'isRecordFormatUpdated isCombinedFormatUpdated'
);
if (!customization.isRecordFormatUpdated && !customization.isCombinedFormatUpdated) {
if (customization && !customization.isRecordFormatUpdated && !customization.isCombinedFormatUpdated) {
await this.updateCustomization.createOrReset(_templateId, {
recordVariables: this.listRecordVariables(userColumns),
destination: template.destination,
Expand Down
7 changes: 7 additions & 0 deletions apps/api/src/app/user/dto/cancel-subscription.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IsArray, IsString } from 'class-validator';

export class CancelSubscriptionDto {
@IsArray()
@IsString({ each: true })
reasons: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import * as dayjs from 'dayjs';
import { Injectable } from '@nestjs/common';
import { DATE_FORMATS } from '@shared/constants';
import { PaymentAPIService } from '@impler/services';
import { EnvironmentRepository } from '@impler/dal';

@Injectable()
export class CancelSubscription {
constructor(private paymentApiService: PaymentAPIService) {}
constructor(
private paymentApiService: PaymentAPIService,
private environmentRepository: EnvironmentRepository
) {}

async execute(userEmail: string) {
const cancelledSubscription = await this.paymentApiService.cancelSubscription(userEmail);
cancelledSubscription.expiryDate = dayjs(cancelledSubscription.expiryDate).format(DATE_FORMATS.COMMON);
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
async execute(projectId: string, cancellationReasons: string[]) {
const teamOwner = await this.environmentRepository.getTeamOwnerDetails(projectId);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const canceledSubscription = await this.paymentApiService.cancelSubscription(teamOwner._userId.email);

return cancelledSubscription;
canceledSubscription.expiryDate = dayjs(canceledSubscription.expiryDate).format(DATE_FORMATS.COMMON);

return canceledSubscription;
}
}
16 changes: 12 additions & 4 deletions apps/api/src/app/user/usecases/checkout/checkout.usecase.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { Injectable } from '@nestjs/common';
import { PaymentAPIService } from '@impler/services';
import { EnvironmentRepository } from '@impler/dal';

@Injectable()
export class Checkout {
constructor(private paymentApiService: PaymentAPIService) {}
constructor(
private paymentApiService: PaymentAPIService,
private environmentRepository: EnvironmentRepository
) {}

async execute({
externalId,
projectId,
paymentMethodId,
planCode,
couponCode,
}: {
externalId: string;
projectId: string;
planCode: string;
paymentMethodId: string;
couponCode?: string;
}) {
const teamOwner = await this.environmentRepository.getTeamOwnerDetails(projectId);

return this.paymentApiService.checkout({
externalId: externalId,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
externalId: teamOwner._userId.email,
planCode: planCode,
paymentMethodId: paymentMethodId,
couponCode: couponCode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Injectable } from '@nestjs/common';
import { PaymentAPIService } from '@impler/services';
import { EnvironmentRepository } from '@impler/dal';

@Injectable()
export class GetTransactionHistory {
constructor(private paymentApiService: PaymentAPIService) {}
constructor(
private paymentApiService: PaymentAPIService,
private environmentRepository: EnvironmentRepository
) {}

async execute(email: string) {
const transactions = await this.paymentApiService.getTransactionHistory(email);
async execute(projectId: string) {
const teamOwner = await this.environmentRepository.getTeamOwnerDetails(projectId);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const transactions = await this.paymentApiService.getTransactionHistory(teamOwner._userId.email);

return transactions.map((transactionItem) => ({
transactionDate: transactionItem.transactionDate,
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/app/user/usecases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GetTransactionHistory } from './get-transaction-history/get-transaction
import { ApplyCoupon } from './apply-coupon/apply-coupon.usecase';
import { Checkout } from './checkout/checkout.usecase';
import { Subscription } from './subscription/subscription.usecase';
import { UpdateSubscriptionPaymentMethod } from './subscription/update-payment-method.usecase';

export const USE_CASES = [
GetImportCounts,
Expand All @@ -22,6 +23,8 @@ export const USE_CASES = [
ApplyCoupon,
Checkout,
Subscription,
UpdatePaymentMethod,
UpdateSubscriptionPaymentMethod,
//
];

Expand All @@ -37,4 +40,5 @@ export {
ApplyCoupon,
Checkout,
Subscription,
UpdateSubscriptionPaymentMethod,
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { Injectable } from '@nestjs/common';
import { PaymentAPIService } from '@impler/services';
import { EnvironmentRepository } from '@impler/dal';

@Injectable()
export class RetrievePaymentMethods {
constructor(private paymentApiService: PaymentAPIService) {}
constructor(
private paymentApiService: PaymentAPIService,
private environmentRepository: EnvironmentRepository
) {}

async execute(email: string) {
return await this.paymentApiService.retriveUserPaymentMethods(email);
async execute(projectId: string) {
const teamOwner = await this.environmentRepository.getTeamOwnerDetails(projectId);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
return await this.paymentApiService.retriveUserPaymentMethods(teamOwner._userId.email);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { Injectable } from '@nestjs/common';
import { PaymentAPIService } from '@impler/services';
import { EnvironmentRepository } from '@impler/dal';

@Injectable()
export class ConfirmIntentId {
constructor(private paymentApiService: PaymentAPIService) {}
constructor(
private paymentApiService: PaymentAPIService,
private environmentRepository: EnvironmentRepository
) {}

async execute(email: string, intentId: string) {
return await this.paymentApiService.confirmPaymentIntentId(email, intentId);
async execute(projectId: string, intentId: string) {
const teamOwner = await this.environmentRepository.getTeamOwnerDetails(projectId);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore

return await this.paymentApiService.confirmPaymentIntentId(teamOwner._userId.email, intentId);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { Injectable } from '@nestjs/common';
import { PaymentAPIService } from '@impler/services';
import { EnvironmentRepository } from '@impler/dal';

@Injectable()
export class UpdatePaymentMethod {
constructor(private paymentApiService: PaymentAPIService) {}
constructor(
private paymentApiService: PaymentAPIService,
private environmentRepository: EnvironmentRepository
) {}

async execute(email: string, paymentId: string) {
return await this.paymentApiService.updatePaymentMethod(email, paymentId);
async execute(projectId: string, paymentMethodId: string) {
const teamOwner = await this.environmentRepository.getTeamOwnerDetails(projectId);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore

return await this.paymentApiService.updatePaymentMethod(teamOwner._userId.email, paymentMethodId);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { PaymentAPIService } from '@impler/services';
import { Injectable } from '@nestjs/common';
import { EnvironmentRepository } from '@impler/dal';

@Injectable()
export class Subscription {
constructor(private paymentApiService: PaymentAPIService) {}
constructor(
private paymentApiService: PaymentAPIService,
private environmentRepository: EnvironmentRepository
) {}

async execute({
email,
projectId,
planCode,
selectedPaymentMethod,
couponCode,
}: {
email: string;
projectId: string;
planCode: string;
selectedPaymentMethod: string;
couponCode?: string;
}) {
const teamOwner = await this.environmentRepository.getTeamOwnerDetails(projectId);

return await this.paymentApiService.subscribe({
planCode,
email,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
email: teamOwner._userId.email,
selectedPaymentMethod,
couponCode,
});
Expand Down
Loading

0 comments on commit e8d7590

Please sign in to comment.