Skip to content

Commit

Permalink
feat: add prp001
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerbera3090 committed Nov 21, 2024
1 parent c753d8e commit 955a7ab
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 38 deletions.
4 changes: 3 additions & 1 deletion packages/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { DrizzleModule } from "./drizzle/drizzle.module";
import { OrganizationModule } from "./feature/organization/organization.module";
import { ProposalModule } from "./feature/proposal/proposal.module";

@Module({
imports: [DrizzleModule],
imports: [DrizzleModule, OrganizationModule, ProposalModule],
controllers: [AppController],
providers: [AppService],
})
Expand Down
77 changes: 50 additions & 27 deletions packages/api/src/drizzle/schema/enum.schema.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,104 @@
import { InferSelectModel } from "drizzle-orm";
import { int, varchar, timestamp, mysqlTable } from "drizzle-orm/mysql-core";

export const OrganizationTypeEnum = mysqlTable("org_typ_e", {
export const OrganizationTypeEnum = mysqlTable("organization_type_enum", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});

export const OrganizationPresidentTypeEnum = mysqlTable("org_pre_typ_e", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});
export const OrganizationPresidentTypeEnum = mysqlTable(
"organization_president_type_enum",
{
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
},
);

export const BudgetDomainEnum = mysqlTable("bud_dom_e", {
export const BudgetDomainEnum = mysqlTable("budget_domain_enum", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});

export const BudgetDivisionIncomeEnum = mysqlTable("bud_div_inc_e", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});
export const BudgetDivisionIncomeEnum = mysqlTable(
"budget_division_income_enum",
{
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
},
);

export const BudgetDivisionExpenseEnum = mysqlTable("bud_div_exp_e", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});
export const BudgetDivisionExpenseEnum = mysqlTable(
"budget_division_expense_enum",
{
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
},
);

export const BudgetClassExpenseEnum = mysqlTable("bud_cla_exp_e", {
export const BudgetClassExpenseEnum = mysqlTable("budget_class_expense_enum", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});

export const TransactionTypeEnum = mysqlTable("tra_typ_e", {
export const TransactionTypeEnum = mysqlTable("transaction_type_enum", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});

export const ReportFileTypeEnum = mysqlTable("rep_fil_typ_e", {
export const ReportFileTypeEnum = mysqlTable("report_file_type_enum", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});

export const AssistantPermissionEnum = mysqlTable("ass_per_e", {
export const AssistantPermissionEnum = mysqlTable("assistant_permission_enum", {
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
});

export const AgendaAcceptedStatusEnum = mysqlTable(
"agenda_accepted_status_enum",
{
id: int("id").autoincrement().primaryKey().notNull(),
name: varchar("name", { length: 30 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
},
);

export type OrganizationTypeEnumT = InferSelectModel<
typeof OrganizationTypeEnum
>;
export type OrganizationPresidentTypeEnumT = InferSelectModel<
typeof OrganizationPresidentTypeEnum
>;
export type AgendaAcceptedStatusEnumT = InferSelectModel<
typeof AgendaAcceptedStatusEnum
>;
4 changes: 4 additions & 0 deletions packages/api/src/drizzle/schema/meeting.schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InferSelectModel } from "drizzle-orm";
import {
int,
varchar,
Expand Down Expand Up @@ -39,3 +40,6 @@ export const Agenda = mysqlTable(
}),
}),
);

export type MeetingT = InferSelectModel<typeof Meeting>;
export type AgendaT = InferSelectModel<typeof Agenda>;
5 changes: 5 additions & 0 deletions packages/api/src/drizzle/schema/organization.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const OrganizationPresident = mysqlTable(
organizationPresidentTypeEnumId: int(
"organization_president_type_enum_id",
).notNull(),
organizationId: int("organization_id").notNull(),
phoneNumber: varchar("phone_number", { length: 20 }).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
Expand All @@ -61,6 +62,10 @@ export const OrganizationPresident = mysqlTable(
columns: [table.userId],
foreignColumns: [User.id],
}),
organizationIdFk: foreignKey({
columns: [table.organizationId],
foreignColumns: [Organization.id],
}),
}),
);

Expand Down
31 changes: 31 additions & 0 deletions packages/api/src/drizzle/schema/proposal.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
mysqlTable,
foreignKey,
} from "drizzle-orm/mysql-core";
import { InferSelectModel } from "drizzle-orm";
import { Organization, Team } from "./organization.schema";
import { Semester } from "./semester.schema";
import { User } from "./user.schema";
Expand Down Expand Up @@ -61,6 +62,7 @@ export const ProjectProposalRevision = mysqlTable(
target: text("target").notNull(),
detail: text("detail").notNull(),
note: text("note"),
agendaId: int("agenda_id"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
deletedAt: timestamp("deleted_at"),
Expand All @@ -79,6 +81,11 @@ export const ProjectProposalRevision = mysqlTable(
foreignColumns: [ProjectProposal.id],
name: "pro_pro_rev_document_id_fk",
}),
agendaIdFk: foreignKey({
columns: [table.agendaId],
foreignColumns: [Agenda.id],
name: "pro_pro_rev_agenda_id_fk",
}),
}),
);

Expand Down Expand Up @@ -299,3 +306,27 @@ export const BudgetProposalExpenseRevision = mysqlTable(
}),
}),
);

export type ProjectProposalT = InferSelectModel<typeof ProjectProposal>;
export type ProjectProposalRevisionT = InferSelectModel<
typeof ProjectProposalRevision
>;
export type ProjectProposalTimelineT = InferSelectModel<
typeof ProjectProposalTimeline
>;
export type OperationProposalT = InferSelectModel<typeof OperationProposal>;
export type OperatingCommitteeProposalT = InferSelectModel<
typeof OperatingCommitteeProposal
>;
export type BudgetProposalIncomeT = InferSelectModel<
typeof BudgetProposalIncome
>;
export type BudgetProposalIncomeRevisionT = InferSelectModel<
typeof BudgetProposalIncomeRevision
>;
export type BudgetProposalExpenseT = InferSelectModel<
typeof BudgetProposalExpense
>;
export type BudgetProposalExpenseRevisionT = InferSelectModel<
typeof BudgetProposalExpenseRevision
>;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

import { OrganizationService } from "../service/organization.service";

@Controller("organization")
@Controller()
export class OrganizationController {
constructor(private readonly organizationService: OrganizationService) {}

Expand Down
9 changes: 8 additions & 1 deletion packages/api/src/feature/organization/organization.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import { DrizzleModule } from "src/drizzle/drizzle.module";
import { SemesterModule } from "src/feature/semester/semester.module";
import { OrganizationService } from "./service/organization.service";
import { OrganizationController } from "./controller/organization.controller";
import { OrganizationPublicService } from "./service/organization.public.service";
import { OrganizationRepository } from "./repository/organization.repository";

@Module({
imports: [DrizzleModule, SemesterModule],
controllers: [OrganizationController],
providers: [OrganizationService],
providers: [
OrganizationService,
OrganizationRepository,
OrganizationPublicService,
],
exports: [OrganizationPublicService],
})
export class OrganizationModule {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, Inject } from "@nestjs/common";
import { and, or, lte, gte, eq } from "drizzle-orm";
import { and, or, lte, gte, eq, isNull } from "drizzle-orm";
import { MySql2Database } from "drizzle-orm/mysql2";
import { DrizzleAsyncProvider } from "src/drizzle/drizzle.provider";

Expand All @@ -8,14 +8,71 @@ import {
OrganizationTypeEnum,
OrganizationT,
OrganizationTypeEnumT,
User,
UserStudent,
OrganizationPresident,
OrganizationPresidentT,
UserT,
UserStudentT,
} from "src/drizzle/schema";

export type OrganizationWithPresidentT = {
organization: OrganizationT;
organizationType: OrganizationTypeEnumT;
president: OrganizationPresidentT;
user: UserT;
userStudent: UserStudentT;
};

@Injectable()
export class OrganizationRepository {
constructor(
@Inject(DrizzleAsyncProvider) private readonly db: MySql2Database,
) {}

async getOrganizationById(id: number): Promise<OrganizationT[]> {
return this.db.select().from(Organization).where(eq(Organization.id, id));
}

async getOrganizationWithPresidentById(
organizationId: number,
date: Date,
): Promise<OrganizationWithPresidentT[]> {
const res = await this.db
.select()
.from(Organization)
.innerJoin(
OrganizationTypeEnum,
eq(Organization.organizationTypeEnumId, OrganizationTypeEnum.id),
)
.innerJoin(
OrganizationPresident,
eq(Organization.id, OrganizationPresident.organizationId),
)
.innerJoin(User, eq(OrganizationPresident.userId, User.id))
.innerJoin(UserStudent, eq(UserStudent.userId, User.id))
.where(
and(
eq(Organization.id, organizationId),
and(
lte(OrganizationPresident.startTerm, date),
or(
gte(OrganizationPresident.endTerm, date),
isNull(OrganizationPresident.endTerm),
),
),
eq(OrganizationPresident.organizationPresidentTypeEnumId, 1),
),
);
return res.map(row => ({
organization: row.organization,
organizationType: row.organization_type_enum,
president: row.organization_president,
user: row.user,
userStudent: row.user_student,
}));
}

async getOrganizationsByTerms(
startTerm: Date,
endTerm: Date,
Expand All @@ -40,11 +97,14 @@ export class OrganizationRepository {
),
and(
lte(Organization.startTerm, endTerm),
eq(Organization.endTerm, null),
isNull(Organization.endTerm),
),
),
);

return res.map(row => ({ ...row, organizationTypeEnum: row.org_typ_e }));
return res.map(row => ({
...row,
organizationTypeEnum: row.organization_type_enum,
}));
}
}
Loading

0 comments on commit 955a7ab

Please sign in to comment.