Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add db transaction interceptor and made it atomic #13

Merged
merged 1 commit into from
Aug 24, 2024
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
20 changes: 13 additions & 7 deletions app/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Module } from '@nestjs/common';
import { dataSrouceOptions } from '../db/data-source';
import { TypeOrmModule } from '@nestjs/typeorm';
import { SubscriptionController } from './controllers/subscription.controller';
import { SubscriptionService } from './services/subscription.service';
import { SubscriptionPlanController } from './controllers/subscription-plan.controller';
import { SubscriptionPlanService } from './services/subscription-plan.service';
import { SubscriptionPlan } from './entities/subscription.entity';
import { CustomerSubscription } from './entities/customer.entity';
import { Invoice } from './entities/invoice.entity';
Expand All @@ -21,9 +21,8 @@ import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { User } from './entities/user.entity';
import { ScheduleModule } from '@nestjs/schedule';
import {
SystemSettingController,
DataLookupController,
} from './controllers/core.controller';
} from './controllers/data-lookup.controller';
import { DataLookupService } from './services/data-lookup.service';
import { SystemSettingService } from './services/setting.service';
import { SystemSetting } from './entities/system-settings.entity';
Expand All @@ -35,6 +34,10 @@ import { PaymentMethod } from './entities/payment-method.entity';
import { StripeService } from './services/stripe.service';
import { BillingService } from './services/billing.service';
import { NotificationsService } from './services/notifications.service';
import { CustomerSubscriptionService } from './services/subscription.service';
import { CustomerSubscriptionController } from './controllers/subscription.controller';
import { SystemSettingController } from './controllers/system-setting.controller';
import { WebhooksController } from './controllers/webhooks.controller';

const config = new ConfigService();
@Module({
Expand Down Expand Up @@ -78,13 +81,16 @@ const config = new ConfigService();
),
],
controllers: [
SubscriptionController,
SubscriptionPlanController,
CustomerSubscriptionController,
AuthController,
SystemSettingController,
DataLookupController,
WebhooksController,
],
providers: [
SubscriptionService,
SubscriptionPlanService,
CustomerSubscriptionService,
AuthService,
StripeService,
NotificationsService,
Expand All @@ -100,5 +106,5 @@ const config = new ConfigService();
],
})
export class AppModule {
constructor(private dataSource: DataSource) {}
constructor(private dataSource: DataSource) { }
}
2 changes: 1 addition & 1 deletion app/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ConfigService } from '@nestjs/config';
/**
* Authentication controller that handles user registration, login, and profile retrieval.
*/
@ApiTags('auth')
@ApiTags('Authentication')
@Controller({ path: 'auth', version: new ConfigService().get('API_VERSION') })
export class AuthController {
constructor(private readonly authService: AuthService) {}
Expand Down
196 changes: 0 additions & 196 deletions app/src/controllers/core.controller.ts

This file was deleted.

78 changes: 78 additions & 0 deletions app/src/controllers/data-lookup.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
Controller,
Post,
Body,
Get,
Param,
Req,
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CreateDataLookupDto } from '../dtos/core.dto';
import { DataLookupService } from '../services/data-lookup.service';
import { ConfigService } from '@nestjs/config';

const config = new ConfigService();

/**
* Controller for managing lookup data.
*/
@ApiTags('Configurations')
@Controller({ path: 'core/lookup-data', version: config.get('API_VERSION') })
export class DataLookupController {
constructor(private readonly dataLookupService: DataLookupService) { }

/**
* Creates a new data lookup entry.
*
* @param createDataLookupDto - DTO containing the data to create a new data lookup entry.
* @param req - The HTTP request object, which contains the transaction manager.
* @returns The newly created DataLookup entity.
*/
@Post()
@ApiOperation({ summary: 'Create a new data lookup entry' })
async create(@Body() createDataLookupDto: CreateDataLookupDto, @Req() req: any) {
const entityManager = req.transactionManager;
return this.dataLookupService.create(createDataLookupDto, entityManager);
}

/**
* Creates multiple data lookup entries in bulk.
*
* @param createDataLookupDtos - Array of DTOs containing the data to create multiple data lookup entries.
* @param req - The HTTP request object, which contains the transaction manager.
* @returns An array of created DataLookup entities.
*/
@Post('bulk')
@ApiOperation({ summary: 'Create multiple data lookup entries in bulk' })
async createBulk(@Body() createDataLookupDtos: CreateDataLookupDto[], @Req() req: any) {
const entityManager = req.transactionManager;
return this.dataLookupService.createBulk(createDataLookupDtos, entityManager);
}

/**
* Retrieves all data lookup entries.
*
* @param req - The HTTP request object, which contains the transaction manager.
* @returns An array of DataLookup entities.
*/
@Get()
@ApiOperation({ summary: 'Retrieve all data lookup entries' })
async findAll(@Req() req: any) {
const entityManager = req.transactionManager;
return this.dataLookupService.findAll(entityManager);
}

/**
* Retrieves a single data lookup entry by ID.
*
* @param id - The ID of the data lookup entry to retrieve.
* @param req - The HTTP request object, which contains the transaction manager.
* @returns The found DataLookup entity.
*/
@Get(':id')
@ApiOperation({ summary: 'Retrieve a single data lookup entry by ID' })
async findOne(@Param('id') id: string, @Req() req: any) {
const entityManager = req.transactionManager;
return this.dataLookupService.findOne(id, entityManager);
}
}
Loading
Loading