Skip to content

Fix lint errors and correct path #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions prisma/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let projectCategoryMap: Record<string, ProjectTypeMap> = {};
let reviewItemCommentTypeMap: Record<string, string> = {};

// Global submission map to store submission information.
let submissionMap: Record<string, Record<string, string>> = {};
const submissionMap: Record<string, Record<string, string>> = {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reviewing other variables in the file to ensure consistent use of const where appropriate. Changing let to const is a good practice when the variable is not reassigned, but consistency across similar variables can improve readability and maintainability.


// Data lookup maps
// Initialize maps from files if they exist, otherwise create new maps
Expand Down Expand Up @@ -287,15 +287,15 @@ function processLookupFiles() {
/**
* Read submission data from resource_xxx.json, upload_xxx.json and submission_xxx.json.
*/
async function initSubmissionMap() {
function initSubmissionMap() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function initSubmissionMap was changed from async to a regular function. Ensure that there are no asynchronous operations within this function that require the use of await. If there are, the function should remain async to handle promises correctly.

// read submission_x.json, read {uploadId -> submissionId} map.
const submissionRegex = new RegExp(`^submission_\\d+\\.json`);
const uploadRegex = new RegExp(`^upload_\\d+\\.json`);
const resourceRegex = new RegExp(`^resource_\\d+\\.json`);
const submissionFiles: string[] = [];
const uploadFiles: string[] = [];
const resourceFiles: string[] = [];
fs.readdirSync(DATA_DIR).filter(f => {
fs.readdirSync(DATA_DIR).filter((f) => {
if (submissionRegex.test(f)) {
submissionFiles.push(f);
}
Expand All @@ -313,14 +313,14 @@ async function initSubmissionMap() {
const filePath = path.join(DATA_DIR, f);
console.log(`Reading submission data from ${f}`);
const jsonData = readJson(filePath)['submission'];
for (let d of jsonData) {
for (const d of jsonData) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using const for the variable jsonData on line 315 since its value is not reassigned.

if (d['submission_status_id'] === '1' && d['upload_id']) {
submissionCount += 1;
// find submission has score and most recent
const item = {
score: d['screening_score'] || d['initial_score'] || d['final_score'],
created: d['create_date'],
submissionId: d['submission_id']
submissionId: d['submission_id'],
};
if (uploadSubmissionMap[d['upload_id']]) {
// existing submission info
Expand All @@ -342,12 +342,17 @@ async function initSubmissionMap() {
const filePath = path.join(DATA_DIR, f);
console.log(`Reading upload data from ${f}`);
const jsonData = readJson(filePath)['upload'];
for (let d of jsonData) {
if (d['upload_status_id'] === '1' && d['upload_type_id'] === '1' && d['resource_id']) {
for (const d of jsonData) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using const instead of let for d since it is not reassigned within the loop.

if (
d['upload_status_id'] === '1' &&
d['upload_type_id'] === '1' &&
d['resource_id']
) {
// get submission info
uploadCount += 1
uploadCount += 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistent use of semicolons throughout the code. A semicolon was added here, so verify other parts of the code for consistency.

if (uploadSubmissionMap[d['upload_id']]) {
resourceSubmissionMap[d['resource_id']] = uploadSubmissionMap[d['upload_id']];
resourceSubmissionMap[d['resource_id']] =
uploadSubmissionMap[d['upload_id']];
}
}
}
Expand All @@ -361,7 +366,7 @@ async function initSubmissionMap() {
const filePath = path.join(DATA_DIR, f);
console.log(`Reading resource data from ${f}`);
const jsonData = readJson(filePath)['resource'];
for (let d of jsonData) {
for (const d of jsonData) {
const projectId = d['project_id'];
const userId = d['user_id'];
const resourceId = d['resource_id'];
Expand All @@ -387,16 +392,17 @@ async function initSubmissionMap() {
}
}
}
console.log(`Read resource count: ${resourceCount}, submission resource count: ${validResourceCount}`);
console.log(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console.log statement has been split into multiple lines. Consider keeping it on a single line for better readability unless it exceeds the maximum line length.

`Read resource count: ${resourceCount}, submission resource count: ${validResourceCount}`,
);
// print summary
let totalSubmissions = 0;
Object.keys(submissionMap).forEach(c => {
Object.keys(submissionMap).forEach((c) => {
totalSubmissions += Object.keys(submissionMap[c]).length;
});
console.log(`Found total submissions: ${totalSubmissions}`);
}


// Process a single type: find matching files, transform them one by one, and then insert in batches.
async function processType(type: string, subtype?: string) {
const regex = new RegExp(`^${type}_\\d+\\.json$`);
Expand Down Expand Up @@ -1050,7 +1056,7 @@ async function migrate() {

// init resource-submission data
console.log('Starting resource/submission import...');
await initSubmissionMap();
initSubmissionMap();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The await keyword has been removed from the initSubmissionMap() call. If initSubmissionMap() is an asynchronous function and its completion is necessary before proceeding, consider adding await back to ensure the function completes before moving on to the next steps.

console.log('Resource/Submission import completed.');

console.log('Starting data import...');
Expand Down
8 changes: 6 additions & 2 deletions src/api/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ import { ChallengeApiService } from 'src/shared/modules/global/challenge.service
ProjectResultController,
ReviewOpportunityController,
ReviewApplicationController,
ReviewHistoryController
ReviewHistoryController,
],
providers: [
ReviewOpportunityService,
ReviewApplicationService,
ChallengeApiService,
],
providers: [ReviewOpportunityService, ReviewApplicationService, ChallengeApiService],
})
export class ApiModule {}
98 changes: 61 additions & 37 deletions src/api/appeal/appeal.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { PrismaErrorService } from '../../shared/modules/global/prisma-error.ser

@ApiTags('Appeal')
@ApiBearerAuth()
@Controller('/api/appeals')
@Controller('/appeals')
export class AppealController {
private readonly logger: LoggerService;

Expand Down Expand Up @@ -74,7 +74,10 @@ export class AppealController {
this.logger.log(`Appeal created with ID: ${data.id}`);
return data as AppealResponseDto;
} catch (error) {
const errorResponse = this.prismaErrorService.handleError(error, 'creating appeal');
const errorResponse = this.prismaErrorService.handleError(
error,
'creating appeal',
);
throw new InternalServerErrorException({
message: errorResponse.message,
code: errorResponse.code,
Expand Down Expand Up @@ -111,15 +114,18 @@ export class AppealController {
this.logger.log(`Appeal updated successfully: ${appealId}`);
return data as AppealResponseDto;
} catch (error) {
const errorResponse = this.prismaErrorService.handleError(error, `updating appeal ${appealId}`);

const errorResponse = this.prismaErrorService.handleError(
error,
`updating appeal ${appealId}`,
);

if (errorResponse.code === 'RECORD_NOT_FOUND') {
throw new NotFoundException({
message: `Appeal with ID ${appealId} was not found`,
code: errorResponse.code
throw new NotFoundException({
message: `Appeal with ID ${appealId} was not found`,
code: errorResponse.code,
});
}

throw new InternalServerErrorException({
message: errorResponse.message,
code: errorResponse.code,
Expand Down Expand Up @@ -147,15 +153,18 @@ export class AppealController {
this.logger.log(`Appeal deleted successfully: ${appealId}`);
return { message: `Appeal ${appealId} deleted successfully.` };
} catch (error) {
const errorResponse = this.prismaErrorService.handleError(error, `deleting appeal ${appealId}`);

const errorResponse = this.prismaErrorService.handleError(
error,
`deleting appeal ${appealId}`,
);

if (errorResponse.code === 'RECORD_NOT_FOUND') {
throw new NotFoundException({
message: `Appeal with ID ${appealId} was not found`,
code: errorResponse.code
throw new NotFoundException({
message: `Appeal with ID ${appealId} was not found`,
code: errorResponse.code,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing comma is unnecessary in the object literal. Consider removing it for consistency with the rest of the code style.

});
}

throw new InternalServerErrorException({
message: errorResponse.message,
code: errorResponse.code,
Expand Down Expand Up @@ -205,15 +214,18 @@ export class AppealController {
this.logger.log(`Appeal response created for appeal ID: ${appealId}`);
return data.appealResponse as AppealResponseResponseDto;
} catch (error) {
const errorResponse = this.prismaErrorService.handleError(error, `creating response for appeal ${appealId}`);

const errorResponse = this.prismaErrorService.handleError(
error,
`creating response for appeal ${appealId}`,
);

if (errorResponse.code === 'RECORD_NOT_FOUND') {
throw new NotFoundException({
message: `Appeal with ID ${appealId} was not found`,
code: errorResponse.code
throw new NotFoundException({
message: `Appeal with ID ${appealId} was not found`,
code: errorResponse.code,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the trailing comma after errorResponse.code to adhere to standard JavaScript object syntax.

});
}

throw new InternalServerErrorException({
message: errorResponse.message,
code: errorResponse.code,
Expand Down Expand Up @@ -253,18 +265,23 @@ export class AppealController {
where: { id: appealResponseId },
data: mapAppealResponseRequestToDto(body),
});
this.logger.log(`Appeal response updated successfully: ${appealResponseId}`);
this.logger.log(
`Appeal response updated successfully: ${appealResponseId}`,
);
return data as AppealResponseRequestDto;
} catch (error) {
const errorResponse = this.prismaErrorService.handleError(error, `updating appeal response ${appealResponseId}`);

const errorResponse = this.prismaErrorService.handleError(
error,
`updating appeal response ${appealResponseId}`,
);

if (errorResponse.code === 'RECORD_NOT_FOUND') {
throw new NotFoundException({
message: `Appeal response with ID ${appealResponseId} was not found`,
code: errorResponse.code
throw new NotFoundException({
message: `Appeal response with ID ${appealResponseId} was not found`,
code: errorResponse.code,
});
}

throw new InternalServerErrorException({
message: errorResponse.message,
code: errorResponse.code,
Expand Down Expand Up @@ -306,18 +323,20 @@ export class AppealController {
@Query('reviewId') reviewId?: string,
@Query() paginationDto?: PaginationDto,
): Promise<PaginatedResponse<AppealResponseDto>> {
this.logger.log(`Getting appeals with filters - resourceId: ${resourceId}, challengeId: ${challengeId}, reviewId: ${reviewId}`);

this.logger.log(
`Getting appeals with filters - resourceId: ${resourceId}, challengeId: ${challengeId}, reviewId: ${reviewId}`,
);

const { page = 1, perPage = 10 } = paginationDto || {};
const skip = (page - 1) * perPage;

try {
// Build where clause for filtering
const whereClause: any = {};
if (resourceId) whereClause.resourceId = resourceId;
if (challengeId) whereClause.challengeId = challengeId;
if (reviewId) whereClause.appealId = reviewId;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition if (reviewId) whereClause.appealId = reviewId; seems to be setting appealId instead of reviewId. Verify if this is intentional or if it should be whereClause.reviewId = reviewId;.


const [appeals, totalCount] = await Promise.all([
this.prisma.appealResponse.findMany({
where: whereClause,
Expand All @@ -326,11 +345,13 @@ export class AppealController {
}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of the closing bracket on line 345 should match the opening bracket on line 326 for better readability.

this.prisma.appealResponse.count({
where: whereClause,
})
}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of the closing bracket on line 348 should match the opening bracket on line 346 for consistency.

]);

this.logger.log(`Found ${appeals.length} appeals (page ${page} of ${Math.ceil(totalCount / perPage)})`);


this.logger.log(
`Found ${appeals.length} appeals (page ${page} of ${Math.ceil(totalCount / perPage)})`,
);

return {
data: appeals.map((appeal) => ({
...appeal,
Expand All @@ -341,10 +362,13 @@ export class AppealController {
perPage,
totalCount,
totalPages: Math.ceil(totalCount / perPage),
}
},
};
} catch (error) {
const errorResponse = this.prismaErrorService.handleError(error, 'fetching appeals');
const errorResponse = this.prismaErrorService.handleError(
error,
'fetching appeals',
);
throw new InternalServerErrorException({
message: errorResponse.message,
code: errorResponse.code,
Expand Down
6 changes: 3 additions & 3 deletions src/api/contact/contactRequests.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import { PrismaService } from '../../shared/modules/global/prisma.service';

@ApiTags('Contact Requests')
@ApiBearerAuth()
@Controller('/api')
@Controller('/')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the controller path from /api to / might affect the routing of the application. Ensure that this change is intentional and that all routes are correctly updated to reflect this new path.

export class ContactRequestsController {
constructor(private readonly prisma: PrismaService) {}

@Post('/contact-requests')
@Roles(UserRole.Submitter, UserRole.Reviewer)
@Scopes(Scope.CreateContactRequest)
@ApiOperation({
@ApiOperation({
summary: 'Create a new contact request',
description: 'Roles: Submitter, Reviewer | Scopes: create:contact-request'
description: 'Roles: Submitter, Reviewer | Scopes: create:contact-request',
})
@ApiBody({ description: 'Contact request body', type: ContactRequestDto })
@ApiResponse({
Expand Down
2 changes: 1 addition & 1 deletion src/api/health-check/healthCheck.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class GetHealthCheckResponseDto {
}

@ApiTags('Healthcheck')
@Controller('/api')
@Controller('/')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from @Controller('/api') to @Controller('/') alters the base path for the health check endpoint. Ensure that this change aligns with the intended routing structure and does not inadvertently affect other endpoints or the application's routing logic.

export class HealthCheckController {
constructor(private readonly prisma: PrismaService) {}

Expand Down
Loading