Skip to content

Commit

Permalink
feat(subscription-service): remove sonar issues
Browse files Browse the repository at this point in the history
remove sonar issues

BREAKING CHANGE:
yes

gh-34
  • Loading branch information
Tyagi-Sunny committed Sep 10, 2024
1 parent 2f5dcc7 commit 4db5c4b
Show file tree
Hide file tree
Showing 24 changed files with 468 additions and 307 deletions.
281 changes: 205 additions & 76 deletions package-lock.json

Large diffs are not rendered by default.

99 changes: 78 additions & 21 deletions services/subscription-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,82 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

import { inject, Binding } from "@loopback/context";
import { Component, CoreBindings, ProviderMap, ServiceOrProviderClass, ControllerClass } from "@loopback/core";
import { Class, Repository, Model } from "@loopback/repository";
import { RestApplication } from "@loopback/rest";
import { CoreComponent, SECURITY_SCHEME_SPEC, ServiceSequence, BearerVerifierBindings, BearerVerifierType, BearerVerifierConfig, BearerVerifierComponent } from "@sourceloop/core";
import { FeatureToggleBindings, FeatureToggleServiceComponent } from "@sourceloop/feature-toggle-service";
import { BillingComponent } from "@local/billing";
import { AuthenticationComponent } from "loopback4-authentication";
import { AuthorizationBindings, AuthorizationComponent } from "loopback4-authorization";
import { BillinCycleController, HomePageController, PingController, CurrencyController, PlanController, ResourceController, ServiceController, SubscriptionController, PlanSubscriptionController, PlanSizesController, PlanFeaturesController } from "./controllers";
import { SubscriptionServiceBindings, SYSTEM_USER, WEBHOOK_VERIFIER } from "./keys";
import { BillingCycle, Currency, Plan, Resource, BillingCustomer, Invoice, Service, Subscription, PlanSizes } from "./models";
import { BillingCycleRepository, CurrencyRepository, PlanRepository, ResourceRepository, ServiceRepository, SubscriptionRepository, PlanSizesRepository, BillingCustomerRepository, InvoiceRepository } from "./repositories";
import { ISubscriptionServiceConfig } from "./types";
import { WebhookVerifierProvider } from "./interceptors/webhook-verifier.interceptor";
import { SystemUserProvider } from "./providers";
import { BillingCustomerController } from "./controllers/billing-customer.controller";
import { BillingInvoiceController } from "./controllers/billing-invoice.controller";
import { BillingPaymentSourceController } from "./controllers/billing-payment-source.controller";
import { WebhookController } from "./controllers/webhook.controller";
import {inject, Binding} from '@loopback/context';
import {
Component,
CoreBindings,
ProviderMap,
ServiceOrProviderClass,
ControllerClass,
} from '@loopback/core';
import {Class, Repository, Model} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {
CoreComponent,
SECURITY_SCHEME_SPEC,
ServiceSequence,
BearerVerifierBindings,
BearerVerifierType,
BearerVerifierConfig,
BearerVerifierComponent,
} from '@sourceloop/core';
import {
FeatureToggleBindings,
FeatureToggleServiceComponent,
} from '@sourceloop/feature-toggle-service';
import {BillingComponent} from '@local/billing';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';
import {
BillinCycleController,
HomePageController,
PingController,
CurrencyController,
PlanController,
ResourceController,
ServiceController,
SubscriptionController,
PlanSubscriptionController,
PlanSizesController,
PlanFeaturesController,
} from './controllers';
import {
SubscriptionServiceBindings,
SYSTEM_USER,
WEBHOOK_VERIFIER,
} from './keys';
import {
BillingCycle,
Currency,
Plan,
Resource,
BillingCustomer,
Invoice,
Service,
Subscription,
PlanSizes,
} from './models';
import {
BillingCycleRepository,
CurrencyRepository,
PlanRepository,
ResourceRepository,
ServiceRepository,
SubscriptionRepository,
PlanSizesRepository,
BillingCustomerRepository,
InvoiceRepository,
} from './repositories';
import {ISubscriptionServiceConfig} from './types';
import {WebhookVerifierProvider} from './interceptors/webhook-verifier.interceptor';
import {SystemUserProvider} from './providers';
import {BillingCustomerController} from './controllers/billing-customer.controller';
import {BillingInvoiceController} from './controllers/billing-invoice.controller';
import {BillingPaymentSourceController} from './controllers/billing-payment-source.controller';
import {WebhookController} from './controllers/webhook.controller';

export class SubscriptionServiceComponent implements Component {
constructor(
Expand Down Expand Up @@ -68,7 +124,8 @@ export class SubscriptionServiceComponent implements Component {
ResourceRepository,
ServiceRepository,
SubscriptionRepository,
PlanSizesRepository,BillingCustomerRepository,
PlanSizesRepository,
BillingCustomerRepository,
InvoiceRepository,
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import {
BillingComponentBindings,
IService
} from '@local/billing';
import { inject } from '@loopback/core';
import {
Filter,
repository
} from '@loopback/repository';
import {BillingComponentBindings, IService} from '@local/billing';
import {inject} from '@loopback/core';
import {Filter, repository} from '@loopback/repository';
import {
del,
get,
getModelSchemaRef,
param,
patch,
post,
requestBody
requestBody,
} from '@loopback/rest';
import { OPERATION_SECURITY_SPEC, STATUS_CODE } from '@sourceloop/core';
import { authenticate, STRATEGY } from 'loopback4-authentication';
import { authorize } from 'loopback4-authorization';
import { AddressDto } from '../models';
import { BillingCustomer } from '../models/billing-customer.model';
import { CustomerDto } from '../models/dto/customer-dto.model';
import { PermissionKey } from '../permissions';
import { InvoiceRepository } from '../repositories';
import { BillingCustomerRepository } from '../repositories/billing-customer.repository';
import {OPERATION_SECURITY_SPEC, STATUS_CODE} from '@sourceloop/core';
import {authenticate, STRATEGY} from 'loopback4-authentication';
import {authorize} from 'loopback4-authorization';
import {AddressDto} from '../models';
import {BillingCustomer} from '../models/billing-customer.model';
import {CustomerDto} from '../models/dto/customer-dto.model';
import {PermissionKey} from '../permissions';
import {InvoiceRepository} from '../repositories';
import {BillingCustomerRepository} from '../repositories/billing-customer.repository';

const basePath = '/billing-customer';
export class BillingCustomerController {
Expand Down Expand Up @@ -80,22 +74,22 @@ export class BillingCustomerController {
}),
);
return new CustomerDto({
id:customer.id,
first_name: customer.first_name,
last_name: customer.last_name,
id: customer.id,
firstName: customer.firstName,
lastName: customer.lastName,
email: customer.email,
company: customer.company,
phone: customer.phone,
billing_address: new AddressDto({
first_name: customer.billing_address?.first_name,
last_name: customer.billing_address?.last_name,
email: customer.billing_address?.email,
company: customer.billing_address?.company,
phone: customer.billing_address?.phone,
city: customer.billing_address?.city,
state: customer.billing_address?.state,
zip: customer.billing_address?.zip,
country: customer.billing_address?.country,
billingAddress: new AddressDto({
firstName: customer.billingAddress?.firstName,
lastName: customer.billingAddress?.lastName,
email: customer.billingAddress?.email,
company: customer.billingAddress?.company,
phone: customer.billingAddress?.phone,
city: customer.billingAddress?.city,
state: customer.billingAddress?.state,
zip: customer.billingAddress?.zip,
country: customer.billingAddress?.country,
}),
});
}
Expand All @@ -116,38 +110,37 @@ export class BillingCustomerController {
},
})
async getCustomer(
@param.filter(BillingCustomer) filter?:Filter<BillingCustomer>
): Promise<{customerDetails:CustomerDto,
info:BillingCustomer
}> {
const customers = await this.billingCustomerRepository.find(
filter
);
@param.filter(BillingCustomer) filter?: Filter<BillingCustomer>,
): Promise<{customerDetails: CustomerDto; info: BillingCustomer}> {
const customers = await this.billingCustomerRepository.find(filter);
if (customers.length == 0) {
throw new Error(' Customer with tenantId is not present');
}

const customer = await this.billingProvider.getCustomers(
customers[0].customerId,
);
return {customerDetails:new CustomerDto({
first_name: customer.first_name,
last_name: customer.last_name,
email: customer.email,
company: customer.company,
phone: customer.phone,
billing_address: new AddressDto({
first_name: customer.billing_address?.first_name,
last_name: customer.billing_address?.last_name,
email: customer.billing_address?.email,
company: customer.billing_address?.company,
phone: customer.billing_address?.phone,
city: customer.billing_address?.city,
state: customer.billing_address?.state,
zip: customer.billing_address?.zip,
country: customer.billing_address?.country,
return {
customerDetails: new CustomerDto({
firstName: customer.firstName,
lastName: customer.lastName,
email: customer.email,
company: customer.company,
phone: customer.phone,
billingAddress: new AddressDto({
firstName: customer.billingAddress?.firstName,
lastName: customer.billingAddress?.lastName,
email: customer.billingAddress?.email,
company: customer.billingAddress?.company,
phone: customer.billingAddress?.phone,
city: customer.billingAddress?.city,
state: customer.billingAddress?.state,
zip: customer.billingAddress?.zip,
country: customer.billingAddress?.country,
}),
}),
}),info:customers[0]};
info: customers[0],
};
}

@authorize({
Expand Down Expand Up @@ -180,7 +173,7 @@ export class BillingCustomerController {
});

if (customers.length == 0) {
throw new Error(' Customer with tenantId is not present');
throw new Error('Customer with tenantId is not present');
}
await this.billingProvider.updateCustomerById(
customers[0].customerId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
BillingComponentBindings,
IService
} from '@local/billing';
import { inject } from '@loopback/core';
import { repository } from '@loopback/repository';
import {BillingComponentBindings, IService} from '@local/billing';
import {inject} from '@loopback/core';
import {repository} from '@loopback/repository';
import {
del,
get,
Expand All @@ -13,15 +10,15 @@ import {
post,
requestBody,
} from '@loopback/rest';
import { OPERATION_SECURITY_SPEC, STATUS_CODE } from '@sourceloop/core';
import { authenticate, STRATEGY } from 'loopback4-authentication';
import { authorize } from 'loopback4-authorization';
import { AddressDto, ChargeDto } from '../models';
import { InvoiceDto } from '../models/dto/invoice-dto.model';
import { TransactionDto } from '../models/dto/transaction-dto.model';
import { PermissionKey } from '../permissions';
import { InvoiceRepository } from '../repositories';
import { BillingCustomerRepository } from '../repositories/billing-customer.repository';
import {OPERATION_SECURITY_SPEC, STATUS_CODE} from '@sourceloop/core';
import {authenticate, STRATEGY} from 'loopback4-authentication';
import {authorize} from 'loopback4-authorization';
import {AddressDto, ChargeDto} from '../models';
import {InvoiceDto} from '../models/dto/invoice-dto.model';
import {TransactionDto} from '../models/dto/transaction-dto.model';
import {PermissionKey} from '../permissions';
import {InvoiceRepository} from '../repositories';
import {BillingCustomerRepository} from '../repositories/billing-customer.repository';

const basePath = '/billing-invoice';
export class BillingInvoiceController {
Expand Down Expand Up @@ -63,7 +60,7 @@ export class BillingInvoiceController {
invoiceDto: Omit<InvoiceDto, 'id' | 'status'>,
): Promise<InvoiceDto> {
const customer = await this.billingCustomerRepository.find({
where: {customerId: invoiceDto.customer_id},
where: {customerId: invoiceDto.customerId},
});

if (customer.length == 0) {
Expand All @@ -75,26 +72,26 @@ export class BillingInvoiceController {
new ChargeDto({amount: charge.amount, description: charge.description}),
);

const invoiceInfo=await this.invoiceRepository.create({
const invoiceInfo = await this.invoiceRepository.create({
invoiceId: invoice.id,
invoiceStatus: invoice.status,
billingCustomerId: customer[0].id,
});
return new InvoiceDto({
id:invoiceInfo.id, // passed the id of invoice info created in our db, to setup relation between subscription and invoice
customer_id: invoice.customer_id,
id: invoiceInfo.id, // passed the id of invoice info created in our db, to setup relation between subscription and invoice
customerId: invoice.customerId,
charges: charges,
status: invoice.status,
shipping_address: new AddressDto({
first_name: invoice.shipping_address?.first_name ?? '',
last_name: invoice.shipping_address?.last_name ?? '',
email: invoice.shipping_address?.email ?? '',
company: invoice.shipping_address?.company,
phone: invoice.shipping_address?.phone,
city: invoice.shipping_address?.city ?? '',
state: invoice.shipping_address?.state ?? '',
zip: invoice.shipping_address?.zip ?? '',
country: invoice.shipping_address?.country ?? '',
shippingAddress: new AddressDto({
firstName: invoice.shippingAddress?.firstName ?? '',
lastName: invoice.shippingAddress?.lastName ?? '',
email: invoice.shippingAddress?.email ?? '',
company: invoice.shippingAddress?.company,
phone: invoice.shippingAddress?.phone,
city: invoice.shippingAddress?.city ?? '',
state: invoice.shippingAddress?.state ?? '',
zip: invoice.shippingAddress?.zip ?? '',
country: invoice.shippingAddress?.country ?? '',
}),
options: invoice.options,
});
Expand Down Expand Up @@ -124,19 +121,19 @@ export class BillingInvoiceController {
new ChargeDto({amount: charge.amount, description: charge.description}),
);
return new InvoiceDto({
customer_id: invoice.customer_id,
customerId: invoice.customerId,
charges: charges,
status: invoice.status,
shipping_address: new AddressDto({
first_name: invoice.shipping_address?.first_name ?? '',
last_name: invoice.shipping_address?.last_name ?? '',
email: invoice.shipping_address?.email ?? '',
company: invoice.shipping_address?.company,
phone: invoice.shipping_address?.phone,
city: invoice.shipping_address?.city ?? '',
state: invoice.shipping_address?.state ?? '',
zip: invoice.shipping_address?.zip ?? '',
country: invoice.shipping_address?.country ?? '',
shippingAddress: new AddressDto({
firstName: invoice.shippingAddress?.firstName ?? '',
lastName: invoice.shippingAddress?.lastName ?? '',
email: invoice.shippingAddress?.email ?? '',
company: invoice.shippingAddress?.company,
phone: invoice.shippingAddress?.phone,
city: invoice.shippingAddress?.city ?? '',
state: invoice.shippingAddress?.state ?? '',
zip: invoice.shippingAddress?.zip ?? '',
country: invoice.shippingAddress?.country ?? '',
}),
options: invoice.options,
});
Expand Down Expand Up @@ -195,13 +192,11 @@ export class BillingInvoiceController {
})
transactionDto: TransactionDto,
): Promise<void> {

const invoiceInfo=await this.invoiceRepository.findById(invoiceId);
const invoiceInfo = await this.invoiceRepository.findById(invoiceId);
await this.billingProvider.applyPaymentSourceForInvoice(
invoiceInfo.invoiceId,
transactionDto
transactionDto,
);

}

@authorize({
Expand Down
Loading

0 comments on commit 4db5c4b

Please sign in to comment.