-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into 56-impl-post-apis-for-filling-dbs
- Loading branch information
Showing
17 changed files
with
611 additions
and
10 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
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
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
28 changes: 28 additions & 0 deletions
28
packages/api/src/feature/proposal/project-proposal/project-proposal.controller.ts
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,28 @@ | ||
import { Controller, Get, Query, UsePipes } from "@nestjs/common"; | ||
|
||
import { ZodPipe } from "@sparcs-students/api/common/pipes/zod-pipe"; | ||
import { | ||
ApiPrp001ResponseOK, | ||
ApiPrp001RequestUrl, | ||
apiPrp001, | ||
ApiPrp001RequestQuery, | ||
} from "@sparcs-students/interface/api/proposal/index"; | ||
|
||
import { ProjectProposalService } from "./project-proposal.service"; | ||
|
||
@Controller() | ||
export class ProjectProposalController { | ||
constructor( | ||
private readonly projectProposalService: ProjectProposalService, | ||
) {} | ||
|
||
@Get(ApiPrp001RequestUrl) | ||
@UsePipes(new ZodPipe(apiPrp001)) | ||
async getPrpanizationsBySemesterId( | ||
@Query() query: ApiPrp001RequestQuery, | ||
): Promise<ApiPrp001ResponseOK> { | ||
return this.projectProposalService.getProjectProposalsForStudentsBySemesterId( | ||
query, | ||
); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/api/src/feature/proposal/project-proposal/project-proposal.module.ts
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,14 @@ | ||
import { Module } from "@nestjs/common"; | ||
|
||
import { DrizzleModule } from "src/drizzle/drizzle.module"; | ||
import { OrganizationModule } from "src/feature/organization/organization.module"; | ||
import { ProjectProposalRepository } from "./project-proposal.repository"; | ||
import { ProjectProposalService } from "./project-proposal.service"; | ||
import { ProjectProposalController } from "./project-proposal.controller"; | ||
|
||
@Module({ | ||
imports: [OrganizationModule, DrizzleModule], | ||
providers: [ProjectProposalRepository, ProjectProposalService], | ||
controllers: [ProjectProposalController], | ||
}) | ||
export class ProjectProposalModule {} |
93 changes: 93 additions & 0 deletions
93
packages/api/src/feature/proposal/project-proposal/project-proposal.repository.ts
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,93 @@ | ||
import { Injectable, Inject } from "@nestjs/common"; | ||
|
||
import { | ||
Agenda, | ||
ProjectProposal, | ||
ProjectProposalRevision, | ||
} from "@sparcs-students/api/drizzle/schema"; | ||
import { ApiPrp001ResponseOK } from "@sparcs-students/interface/api/proposal/index"; | ||
import { AgendaAcceptedStatusE } from "@sparcs-students/interface/common/enum/meeting.enum"; | ||
|
||
import { and, eq, desc } from "drizzle-orm"; | ||
|
||
import { MySql2Database } from "drizzle-orm/mysql2"; | ||
import { DrizzleAsyncProvider } from "src/drizzle/drizzle.provider"; | ||
|
||
@Injectable() | ||
export class ProjectProposalRepository { | ||
constructor( | ||
@Inject(DrizzleAsyncProvider) private readonly db: MySql2Database, | ||
) {} | ||
|
||
/** | ||
* @param organizationId, semester id | ||
* @returns 해당 동아리와 학기에 해당하는 ProjectProposals list 객체를 리턴합니다. | ||
* @description 이미 사업계획서를 모두 심사한 후를 기준으로 하는 상태로, 일반 학생들도 볼 수 있는 상태입니다. | ||
*/ | ||
async getProjectProposalsForStudentsByOrganizationIdAndSemesterId( | ||
organizationId: number, | ||
semesterId: number, | ||
): Promise<ApiPrp001ResponseOK["projects"]> { | ||
const res = await this.db | ||
.select({ | ||
projectName: ProjectProposalRevision.name, | ||
proposalId: ProjectProposal.id, | ||
startTerm: ProjectProposalRevision.startTerm, | ||
endTerm: ProjectProposalRevision.endTerm, | ||
agendaAccepted: Agenda.accepted, | ||
agendaExists: ProjectProposalRevision.agendaId, | ||
}) | ||
.from(ProjectProposal) | ||
.innerJoin( | ||
ProjectProposalRevision, | ||
eq(ProjectProposal.revisionId, ProjectProposalRevision.id), | ||
) | ||
.leftJoin(Agenda, eq(ProjectProposalRevision.agendaId, Agenda.id)) | ||
.where( | ||
and( | ||
eq(ProjectProposal.organizationId, organizationId), | ||
eq(ProjectProposal.semesterId, semesterId), | ||
), | ||
); | ||
|
||
return res.map(row => ({ | ||
name: row.projectName, | ||
projectProposalId: row.proposalId, | ||
startTerm: row.startTerm, | ||
endTerm: row.endTerm, | ||
acceptedStatus: | ||
row.agendaExists && row.agendaAccepted | ||
? AgendaAcceptedStatusE.Accepted | ||
: AgendaAcceptedStatusE.Reject, | ||
})); | ||
} | ||
|
||
/** | ||
* @param organizationId, semesterId | ||
* @returns 해당 기구 해당 학기에 해당하는 ProjectProposal의 제출연월일을 리턴합니다. | ||
* @description 가장 최근의 제출일을 리턴합니다. | ||
*/ | ||
async getProjectProposalSubmitDate( | ||
organizationId: number, | ||
semesterId: number, | ||
): Promise<Date[]> { | ||
const res = await this.db | ||
.select() | ||
.from(ProjectProposal) | ||
.innerJoin( | ||
ProjectProposalRevision, | ||
eq(ProjectProposal.revisionId, ProjectProposalRevision.id), | ||
) | ||
.innerJoin(Agenda, eq(ProjectProposalRevision.agendaId, Agenda.id)) | ||
.where( | ||
and( | ||
eq(ProjectProposal.semesterId, semesterId), | ||
eq(ProjectProposal.organizationId, organizationId), | ||
), | ||
) | ||
.orderBy(desc(Agenda.submittedAt)) | ||
.limit(1); | ||
|
||
return res.map(row => row.agenda.submittedAt); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/api/src/feature/proposal/project-proposal/project-proposal.service.ts
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,67 @@ | ||
import { | ||
HttpException, | ||
HttpStatus, | ||
Injectable, | ||
NotFoundException, | ||
} from "@nestjs/common"; | ||
|
||
import { | ||
ApiPrp001RequestQuery, | ||
ApiPrp001ResponseOK, | ||
} from "@sparcs-students/interface/api/proposal/index"; | ||
import { OrganizationPublicService } from "src/feature/organization/service/organization.public.service"; | ||
import { ProjectProposalRepository } from "./project-proposal.repository"; | ||
|
||
@Injectable() | ||
export class ProjectProposalService { | ||
constructor( | ||
private readonly projectProposalRepository: ProjectProposalRepository, | ||
private readonly organizationPublicService: OrganizationPublicService, | ||
) {} | ||
|
||
async getProjectProposalsForStudentsBySemesterId( | ||
param: ApiPrp001RequestQuery, | ||
): Promise<ApiPrp001ResponseOK> { | ||
const organizationInfo = | ||
await this.organizationPublicService.getOrganizationWithPresidentByOrganizationIdAndSemesterId( | ||
param.organizationId, | ||
param.semesterId, | ||
); | ||
const projectProposals = | ||
await this.projectProposalRepository.getProjectProposalsForStudentsByOrganizationIdAndSemesterId( | ||
param.organizationId, | ||
param.semesterId, | ||
); | ||
if (projectProposals.length === 0) { | ||
throw new NotFoundException( | ||
`ProjectProposals with Organization ID ${param.organizationId} and semesterId ${param.semesterId} not found`, | ||
); | ||
} | ||
|
||
const submitDate = | ||
await this.projectProposalRepository.getProjectProposalSubmitDate( | ||
param.organizationId, | ||
param.semesterId, | ||
); | ||
if (submitDate.length === 0) { | ||
throw new NotFoundException( | ||
`ProjectProposal submitdate with Organization ID ${param.organizationId} and semesterId ${param.semesterId} not found`, | ||
); | ||
} else if (submitDate.length > 1) { | ||
throw new HttpException( | ||
"unreachable: multiple submitDate", | ||
HttpStatus.INTERNAL_SERVER_ERROR, | ||
); | ||
} | ||
|
||
return { | ||
semesterId: param.semesterId, | ||
organizationId: param.organizationId, | ||
organizationName: organizationInfo.organization.name, | ||
organizationPresidentId: organizationInfo.user.id, | ||
organizationPresidentName: organizationInfo.user.name, | ||
submitDate: submitDate[0], | ||
projects: projectProposals, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { ProjectProposalModule } from "./project-proposal/project-proposal.module"; | ||
|
||
@Module({}) | ||
@Module({ | ||
imports: [ProjectProposalModule], | ||
}) | ||
export class ProposalModule {} |
Oops, something went wrong.