-
-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): add site setting api (#1125)
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Controller, Get, Logger, Param } from '@nestjs/common' | ||
import { ApiOperation, ApiTags } from '@nestjs/swagger' | ||
import { ResponseUtil } from 'src/utils/response' | ||
import { SettingService } from './setting.service' | ||
|
||
@ApiTags('Public') | ||
@Controller('settings') | ||
export class SettingController { | ||
private readonly logger = new Logger(SettingController.name) | ||
|
||
constructor(private readonly settingService: SettingService) {} | ||
|
||
/** | ||
* Get site settings | ||
*/ | ||
@ApiOperation({ summary: 'Get site settings' }) | ||
@Get() | ||
async getSettings() { | ||
const data = await this.settingService.findAll() | ||
return ResponseUtil.ok(data) | ||
} | ||
|
||
/** | ||
* Get one site setting by key | ||
*/ | ||
@ApiOperation({ summary: 'Get one site setting by key' }) | ||
@Get(':key') | ||
async getSettingByKey(@Param('key') key: string) { | ||
const data = await this.settingService.findOne(key) | ||
if (!data) { | ||
return ResponseUtil.error('Setting not found') | ||
} | ||
return ResponseUtil.ok(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common' | ||
import { SettingService } from './setting.service' | ||
import { SettingController } from './setting.controller' | ||
|
||
@Module({ | ||
providers: [SettingService], | ||
controllers: [SettingController], | ||
}) | ||
export class SettingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Injectable, Logger } from '@nestjs/common' | ||
import { PrismaService } from 'src/prisma/prisma.service' | ||
|
||
@Injectable() | ||
export class SettingService { | ||
private readonly logger = new Logger(SettingService.name) | ||
|
||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async findAll() { | ||
return await this.prisma.setting.findMany() | ||
} | ||
|
||
async findOne(key: string) { | ||
return await this.prisma.setting.findUnique({ | ||
where: { key }, | ||
}) | ||
} | ||
} |