@sourceloop/ctrl-plane-subscription-service
Version:
Subscription management microservice for SaaS control plane.
101 lines (96 loc) • 2.83 kB
text/typescript
import {inject} from '@loopback/core';
import {del, get, param, post, requestBody} from '@loopback/rest';
import {
OPERATION_SECURITY_SPEC,
STATUS_CODE,
getModelSchemaRefSF,
} from '@sourceloop/core';
import {authenticate, STRATEGY} from 'loopback4-authentication';
import {authorize} from 'loopback4-authorization';
import {PaymentSourceDto} from '../models/dto/payment-dto.model';
import {PermissionKey} from '../permissions';
import {BillingPaymentSourceService} from '../services/billing-payment-source.service';
const basePath = '/billing-payment-source';
export class BillingPaymentSourceController {
constructor(
('services.BillingPaymentSourceService')
private readonly billingPaymentSourceService: BillingPaymentSourceService,
) {}
({
permissions: [PermissionKey.CreateBillingPaymentSource],
})
(STRATEGY.BEARER, {
passReqToCallback: true,
})
(basePath, {
security: OPERATION_SECURITY_SPEC,
responses: {
[STATUS_CODE.OK]: {
description: 'Payment model instance',
content: {
'application/json': {schema: getModelSchemaRefSF(PaymentSourceDto)},
},
},
},
})
async create(
({
content: {
'application/json': {
schema: getModelSchemaRefSF(PaymentSourceDto, {
title: 'NewPaymentSource',
exclude: ['id'],
}),
},
},
})
paymentSourceDto: PaymentSourceDto,
): Promise<PaymentSourceDto> {
return this.billingPaymentSourceService.createPaymentSource(
paymentSourceDto,
);
}
({
permissions: [PermissionKey.GetBillingPaymentSource],
})
(STRATEGY.BEARER, {
passReqToCallback: true,
})
(basePath, {
security: OPERATION_SECURITY_SPEC,
responses: {
[STATUS_CODE.OK]: {
description: 'get payment source',
content: {
'application/json': {schema: getModelSchemaRefSF(PaymentSourceDto)},
},
},
},
})
async getPaymentSource(
.path.string('paymentSourceId') paymentSourceId: string,
): Promise<PaymentSourceDto> {
return this.billingPaymentSourceService.getPaymentSource(paymentSourceId);
}
({
permissions: [PermissionKey.DeleteBillingPaymentSource],
})
(STRATEGY.BEARER, {
passReqToCallback: true,
})
(`${basePath}/{paymentSourceId}`, {
security: OPERATION_SECURITY_SPEC,
responses: {
[STATUS_CODE.NO_CONTENT]: {
description: 'Billing Payment Source DELETE success',
},
},
})
async deleteById(
.path.string('paymentSourceId') paymentSourceId: string,
): Promise<void> {
return this.billingPaymentSourceService.deletePaymentSource(
paymentSourceId,
);
}
}