Skip to content

Commit

Permalink
Merge pull request #1296 from academic-relations/dev
Browse files Browse the repository at this point in the history
Merge dev into main
  • Loading branch information
pbc1017 authored Jan 3, 2025
2 parents 3073904 + ff81c76 commit 2ee31d8
Show file tree
Hide file tree
Showing 60 changed files with 1,179 additions and 407 deletions.
29 changes: 29 additions & 0 deletions packages/api/src/drizzle/schema/activity.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,35 @@ export const ProfessorSignStatus = mysqlTable(
}),
);

export const ActivityClubChargedExecutive = mysqlTable(
"activity_club_charged_executive",
{
id: int("id").autoincrement().primaryKey().notNull(),
activityDId: int("activity_d_id").notNull(),
clubId: int("club_id").notNull(),
executiveId: int("executive_id"),
createdAt: timestamp("created_at").defaultNow().notNull(),
deletedAt: timestamp("deleted_at"),
},
table => ({
activityForeignKey: foreignKey({
name: "activity_club_charged_executive_activity_d_id_fk",
columns: [table.activityDId],
foreignColumns: [ActivityD.id],
}),
clubForeignKey: foreignKey({
name: "activity_club_charged_executive_club_id_fk",
columns: [table.clubId],
foreignColumns: [Club.id],
}),
executiveForeignKey: foreignKey({
name: "activity_club_charged_executive_executive_id_fk",
columns: [table.executiveId],
foreignColumns: [Executive.id],
}),
}),
);

export const ActivityDeadlineD = mysqlTable(
"activity_deadline_d",
{
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/feature/activity/activity.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UserModule from "../user/user.module";

import ActivityActivityTermController from "./controller/activity.activity-term.controller";
import ActivityController from "./controller/activity.controller";
import ActivityClubChargedExecutiveRepository from "./repository/activity.activity-club-charged-executive.repository";
import ActivityActivityTermRepository from "./repository/activity.activity-term.repository";
import ActivityRepository from "./repository/activity.repository";
import ActivityActivityTermService from "./service/activity.activity-term.service";
Expand All @@ -30,6 +31,7 @@ import ActivityService from "./service/activity.service";
providers: [
ActivityRepository,
ActivityActivityTermRepository,
ActivityClubChargedExecutiveRepository,
ActivityService,
ActivityActivityTermService,
ActivityPublicService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import apiAct020, {
ApiAct020ResponseCreated,
} from "@sparcs-clubs/interface/api/activity/endpoint/apiAct020";
import apiAct023 from "@sparcs-clubs/interface/api/activity/endpoint/apiAct023";
import apiAct024 from "@sparcs-clubs/interface/api/activity/endpoint/apiAct024";
import apiAct025 from "@sparcs-clubs/interface/api/activity/endpoint/apiAct025";
import apiAct026 from "@sparcs-clubs/interface/api/activity/endpoint/apiAct026";

import { ZodPipe } from "@sparcs-clubs/api/common/pipe/zod-pipe";

Expand Down Expand Up @@ -116,6 +119,18 @@ import type {
} from "@sparcs-clubs/interface/api/activity/endpoint/apiAct017";
import type { ApiAct018ResponseOk } from "@sparcs-clubs/interface/api/activity/endpoint/apiAct018";
import type { ApiAct023ResponseOk } from "@sparcs-clubs/interface/api/activity/endpoint/apiAct023";
import type {
ApiAct024RequestQuery,
ApiAct024ResponseOk,
} from "@sparcs-clubs/interface/api/activity/endpoint/apiAct024";
import type {
ApiAct025RequestBody,
ApiAct025ResponseOk,
} from "@sparcs-clubs/interface/api/activity/endpoint/apiAct025";
import type {
ApiAct026RequestBody,
ApiAct026ResponseOk,
} from "@sparcs-clubs/interface/api/activity/endpoint/apiAct026";

@Controller()
export default class ActivityController {
Expand Down Expand Up @@ -398,4 +413,43 @@ export default class ActivityController {
const result = await this.activityService.getExecutiveActivitiesClubs();
return result;
}

@Executive()
@Get("/executive/activities/club-brief")
@UsePipes(new ZodPipe(apiAct024))
async getExecutiveActivitiesClubBrief(
@GetExecutive() user: GetExecutive,
@Query() query: ApiAct024RequestQuery,
): Promise<ApiAct024ResponseOk> {
const result = await this.activityService.getExecutiveActivitiesClubBrief({
query,
});
return result;
}

@Executive()
@Patch("/executive/activities")
@UsePipes(new ZodPipe(apiAct025))
async patchExecutiveActivities(
@GetExecutive() user: GetExecutive,
@Body() body: ApiAct025RequestBody,
): Promise<ApiAct025ResponseOk> {
await this.activityService.patchExecutiveActivities({
body,
});
return {};
}

@Executive()
@Put("/executive/activities/club-charged-executive")
@UsePipes(new ZodPipe(apiAct026))
async putExecutiveActivitiesClubChargedExecutive(
@GetExecutive() user: GetExecutive,
@Body() body: ApiAct026RequestBody,
): Promise<ApiAct026ResponseOk> {
await this.activityService.putExecutiveActivitiesClubChargedExecutive({
body,
});
return {};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Inject, Injectable } from "@nestjs/common";
import { and, eq, isNull } from "drizzle-orm";
import { MySql2Database } from "drizzle-orm/mysql2";

// import logger from "@sparcs-clubs/api/common/util/logger";
import { DrizzleAsyncProvider } from "@sparcs-clubs/api/drizzle/drizzle.provider";
import { ActivityClubChargedExecutive } from "@sparcs-clubs/api/drizzle/schema/activity.schema";

@Injectable()
export default class ActivityClubChargedExecutiveRepository {
constructor(@Inject(DrizzleAsyncProvider) private db: MySql2Database) {}

/**
* @param
* @description 활동기간에 동아리 담당자 매핑을 생성합니다. 이미 해당기간에 담당자가 존재하는
* 동아리는 update를 이용해야하며, 이 메소드를 이용하는경우 담당자가 둘 이상이 며 의도되지 않은
* 동작을 발생시킬 수 있습니다.
* @returns insertion의 성공 여부를 리턴합니다.
*/
async insertActivityClubChargedExecutive(param: {
activityDId: number;
clubId: number;
executiveId?: number | undefined;
}): Promise<boolean> {
const [insertResult] = await this.db
.insert(ActivityClubChargedExecutive)
.values({
activityDId: param.activityDId,
clubId: param.clubId,
executiveId: param.executiveId,
});

return insertResult.affectedRows >= 1;
}

/**
* @param acitvityDId 활동기간 아이디를 받습니다.
* @param clubId 동아리 아이디를 받습니다.
* @returns 해당 활동기간 해당 동아리의 활동보고서 당당 집행부원을 리턴합니다.
* 담당자가 존재하징 않을 수 있습니다. 리턴은 배열 형태이며, 배열의 길이는 1 이하여야 합니다.
*/
async selectActivityClubChargedExecutiveByClubId(param: {
activityDId: number;
clubId: number;
}) {
const result = await this.db
.select()
.from(ActivityClubChargedExecutive)
.where(
and(
eq(ActivityClubChargedExecutive.activityDId, param.activityDId),
eq(ActivityClubChargedExecutive.clubId, param.clubId),
isNull(ActivityClubChargedExecutive.deletedAt),
),
);
return result;
}

/**
* @description 이미 담당자가 존재하는 동아리에 대해 담당자를 변경합니다.
* @param param
* @returns 변경의 성공여부를 리턴합니다.
*/
async updateActivityClubChargedExecutive(param: {
activityDId: number;
clubId: number;
executiveId?: number | undefined;
}): Promise<boolean> {
const [updateResult] = await this.db
.update(ActivityClubChargedExecutive)
.set({
executiveId: param.executiveId,
})
.where(
and(
eq(ActivityClubChargedExecutive.activityDId, param.activityDId),
eq(ActivityClubChargedExecutive.clubId, param.clubId),
isNull(ActivityClubChargedExecutive.deletedAt),
),
);

return updateResult.affectedRows >= 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,7 @@ export default class ActivityRepository {
*/
async selectActivityFeedbackByActivityId(param: { activityId: number }) {
const result = await this.db
.select({
comment: ActivityFeedback.comment,
createdAt: ActivityFeedback.createdAt,
})
.select()
.from(ActivityFeedback)
.where(
and(
Expand Down Expand Up @@ -616,4 +613,26 @@ export default class ActivityRepository {
});
return isUpdateSucceed;
}

/**
* @param activityId 활동 Id
* @param executiveId 집행부원 Id
* @description 해당 활동의 담당 집행부원을 변경합니다.
* @returns update에 성공했는지 성공여부를 리턴합니다.
*/
async updateActivityChargedExecutive(param: {
activityId: number;
executiveId: number;
}): Promise<boolean> {
const [updateResult] = await this.db
.update(Activity)
.set({
chargedExecutiveId: param.executiveId,
})
.where(
and(eq(Activity.id, param.activityId), isNull(Activity.deletedAt)),
);

return updateResult.warningStatus === 0;
}
}
Loading

0 comments on commit 2ee31d8

Please sign in to comment.