- 添加项目图标文件(app-icon.png、各平台图标) - 配置开发环境文件(.env、.nvmrc、.npmrc) - 添加静态资源文件(背景图片、字体、音频) - 初始化Tauri后端结构(build.rs、main.rs、模块文件) - 配置前端项目结构(TypeScript、Vue组件、样式) - 添加Node.js API服务基础结构 - 配置构建和开发工具(vite、prettier、gitignore)
20 lines
659 B
TypeScript
20 lines
659 B
TypeScript
import { HttpException, Injectable, type PipeTransform, UnprocessableEntityException } from '@nestjs/common';
|
|
|
|
@Injectable()
|
|
export class NonEmptyStringPipe implements PipeTransform<string, string> {
|
|
public constructor(
|
|
private readonly name?: string,
|
|
private readonly code: 422 | 423 = 422
|
|
) {}
|
|
public transform(value: unknown): string {
|
|
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
const message = `${this.name ?? '参数'}不能为空`;
|
|
if (this.code === 422) {
|
|
throw new UnprocessableEntityException(message);
|
|
}
|
|
throw new HttpException(message, 423);
|
|
}
|
|
return value.trim();
|
|
}
|
|
}
|