xiaoju-survey/server/src/modules/surveyResponse/controllers/responseSchema.controller.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-01-30 14:19:45 +00:00
import { Controller, Get, HttpCode, Query } from '@nestjs/common';
import { ResponseSchemaService } from '../services/responseScheme.service';
import { HttpException } from 'src/exceptions/httpException';
import { EXCEPTION_CODE } from 'src/enums/exceptionCode';
import { RECORD_STATUS } from 'src/enums';
2024-03-28 13:37:59 +00:00
import { ApiTags } from '@nestjs/swagger';
2024-01-30 14:19:45 +00:00
2024-03-28 13:37:59 +00:00
@ApiTags('surveyResponse')
2024-01-30 14:19:45 +00:00
@Controller('/api/responseSchema')
export class ResponseSchemaController {
constructor(private readonly responseSchemaService: ResponseSchemaService) {}
@Get('/getSchema')
@HttpCode(200)
async getSchema(
@Query()
queryInfo: {
surveyPath: string;
},
) {
if (!queryInfo.surveyPath) {
throw new HttpException('参数有误', EXCEPTION_CODE.PARAMETER_ERROR);
}
const responseSchema =
await this.responseSchemaService.getResponseSchemaByPath(
queryInfo.surveyPath,
);
if (
!responseSchema ||
responseSchema.curStatus.status === RECORD_STATUS.REMOVED
) {
throw new HttpException(
'问卷已删除',
EXCEPTION_CODE.RESPONSE_SCHEMA_REMOVED,
);
}
return {
code: 200,
data: responseSchema,
};
}
}