mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:04:53 +00:00
Add TimeZone module with controller and service
This commit is contained in:
1
src/timezone/controllers/index.ts
Normal file
1
src/timezone/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './timezone.controller';
|
||||||
33
src/timezone/controllers/timezone.controller.ts
Normal file
33
src/timezone/controllers/timezone.controller.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
UseGuards,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { TimeZoneService } from '../services/timezone.service';
|
||||||
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||||
|
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||||
|
|
||||||
|
@ApiTags('TimeZone Module')
|
||||||
|
@Controller({
|
||||||
|
version: '1',
|
||||||
|
path: 'timezone',
|
||||||
|
})
|
||||||
|
export class TimeZoneController {
|
||||||
|
constructor(private readonly timeZoneService: TimeZoneService) {}
|
||||||
|
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@Get()
|
||||||
|
async getAllTimeZones() {
|
||||||
|
try {
|
||||||
|
return await this.timeZoneService.getAllTimeZones();
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
error.message || 'Internal server error',
|
||||||
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/timezone/services/index.ts
Normal file
1
src/timezone/services/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './timezone.service';
|
||||||
25
src/timezone/services/timezone.service.ts
Normal file
25
src/timezone/services/timezone.service.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TimeZoneService {
|
||||||
|
constructor(private readonly timeZoneRepository: TimeZoneRepository) {}
|
||||||
|
async getAllTimeZones() {
|
||||||
|
try {
|
||||||
|
const timeZones = await this.timeZoneRepository.find();
|
||||||
|
|
||||||
|
return timeZones;
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof BadRequestException) {
|
||||||
|
throw err; // Re-throw BadRequestException
|
||||||
|
} else {
|
||||||
|
throw new HttpException('TimeZones found', HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/timezone/timezone.module.ts
Normal file
13
src/timezone/timezone.module.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TimeZoneService } from './services/timezone.service';
|
||||||
|
import { TimeZoneController } from './controllers/timezone.controller';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [ConfigModule],
|
||||||
|
controllers: [TimeZoneController],
|
||||||
|
providers: [TimeZoneService, TimeZoneRepository],
|
||||||
|
exports: [TimeZoneService],
|
||||||
|
})
|
||||||
|
export class TimeZoneModule {}
|
||||||
Reference in New Issue
Block a user