first commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { Column, Entity, PrimaryColumn } from 'typeorm';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EntityHelper } from 'src/utils/entity-helper';
|
||||
|
||||
@Entity()
|
||||
export class Translation extends EntityHelper {
|
||||
@ApiProperty({ example: 1 })
|
||||
@PrimaryColumn()
|
||||
key: string;
|
||||
|
||||
@PrimaryColumn()
|
||||
language: 'de' | 'en';
|
||||
|
||||
@ApiProperty({ example: 'Admin' })
|
||||
@Column()
|
||||
value: string;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TranslateController } from './translate.controller';
|
||||
|
||||
describe('TranslateController', () => {
|
||||
let controller: TranslateController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [TranslateController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<TranslateController>(TranslateController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
16
myteamwallet_backend/src/translate/translate.controller.ts
Normal file
16
myteamwallet_backend/src/translate/translate.controller.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Controller, Get, HttpCode, HttpStatus, Param } from '@nestjs/common';
|
||||
import { TranslateService } from './translate.service';
|
||||
|
||||
@Controller({
|
||||
path: 'translations',
|
||||
version: '1',
|
||||
})
|
||||
export class TranslateController {
|
||||
constructor(private translateService: TranslateService) {}
|
||||
|
||||
@Get(':language')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
getTranslations(@Param('language') language: any) {
|
||||
return this.translateService.getTranslations(language);
|
||||
}
|
||||
}
|
||||
12
myteamwallet_backend/src/translate/translate.module.ts
Normal file
12
myteamwallet_backend/src/translate/translate.module.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Translation } from './model/translation.entity';
|
||||
import { TranslateController } from './translate.controller';
|
||||
import { TranslateService } from './translate.service';
|
||||
|
||||
@Module({
|
||||
controllers: [TranslateController],
|
||||
providers: [TranslateService],
|
||||
imports: [TypeOrmModule.forFeature([Translation])],
|
||||
})
|
||||
export class TranslateModule {}
|
||||
18
myteamwallet_backend/src/translate/translate.service.spec.ts
Normal file
18
myteamwallet_backend/src/translate/translate.service.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TranslateService } from './translate.service';
|
||||
|
||||
describe('TranslateService', () => {
|
||||
let service: TranslateService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [TranslateService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<TranslateService>(TranslateService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
24
myteamwallet_backend/src/translate/translate.service.ts
Normal file
24
myteamwallet_backend/src/translate/translate.service.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Translation } from './model/translation.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TranslateService {
|
||||
constructor(
|
||||
@InjectRepository(Translation)
|
||||
private translationsRepository: Repository<Translation>,
|
||||
) {}
|
||||
|
||||
async getTranslations(language: 'de' | 'en') {
|
||||
const db = await this.translationsRepository.findBy({
|
||||
language: language,
|
||||
});
|
||||
|
||||
const result = {};
|
||||
for (const d of db) {
|
||||
result[d.key] = d.value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user