fix: clarify signature reporting status

This commit is contained in:
hectorzhao
2026-07-13 10:16:12 +08:00
parent 551edfd8ca
commit 344b2afe3b
13 changed files with 140 additions and 26 deletions
@@ -128,4 +128,20 @@ describe('DictionariesService', () => {
);
expect(prisma.drainageField.create).toHaveBeenCalledTimes(1);
});
it('only accepts Arabic numerals and English letters in report field codes', async () => {
const prisma = createPrismaMock();
const service = new DictionariesService(prisma as never);
await expect(service.createDrainageField({ code: 'License2026', name: '营业执照', fieldType: 'image' })).resolves.toEqual(
expect.objectContaining({ code: 'License2026' }),
);
expect(() => service.createDrainageField({ code: 'license_code', name: '营业执照', fieldType: 'image' })).toThrow(
'code must contain only Arabic numerals and English letters',
);
expect(() => service.createDrainageField({ code: '营业执照', name: '营业执照', fieldType: 'image' })).toThrow(
'code must contain only Arabic numerals and English letters',
);
expect(prisma.drainageField.create).toHaveBeenCalledTimes(1);
});
});
+5 -1
View File
@@ -255,12 +255,16 @@ export class DictionariesService {
}
createDrainageField(data: CreateDrainageFieldDto) {
const code = data.code?.trim();
if (!code || !/^[A-Za-z0-9]+$/.test(code)) {
throw new BadRequestException('code must contain only Arabic numerals and English letters');
}
if (!['string', 'image', 'file'].includes(data.fieldType)) {
throw new BadRequestException('fieldType must be string, image or file');
}
return this.prisma.drainageField.create({
data: {
code: data.code,
code,
name: data.name,
fieldType: data.fieldType,
required: data.required ?? false,