Skip to content

Commit

Permalink
Merge pull request #79 from chingu-x/chore/me-endpoint
Browse files Browse the repository at this point in the history
Add status to Voyage table and return in the /me endpoint
  • Loading branch information
cherylli committed Jan 23, 2024
2 parents f0d5e3f + 4105966 commit 8d6fbc1
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RT_SECRET=
MJ_APIKEY_PRIVATE=
MJ_APIKEY_PUBLIC=
NODE_ENV=development
FRONTEND_URL=https://chingu-dashboard.vercel.app
FRONTEND_URL=https://chingu-dashboard-git-dev-chingu-dashboard.vercel.app/
BCRYPT_HASHING_ROUNDS=10

# .env.test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Voyage" ADD COLUMN "statusId" INTEGER;

-- AddForeignKey
ALTER TABLE "Voyage" ADD CONSTRAINT "Voyage_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "VoyageStatus"("id") ON DELETE SET NULL ON UPDATE CASCADE;
17 changes: 10 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ model EmailVerificationToken {
// === Voyage - Schedule, sprint dates and Teams ===

model Voyage {
id Int @id @default(autoincrement())
number String @unique
startDate DateTime @db.Timestamptz()
endDate DateTime @db.Timestamptz()
soloProjectDeadline DateTime @db.Timestamptz()
certificateIssueDate DateTime @db.Timestamptz()
showcasePublishDate DateTime? @db.Timestamptz()
id Int @id @default(autoincrement())
number String @unique
status VoyageStatus? @relation(fields: [statusId], references: [id], onDelete: SetNull)
statusId Int?
startDate DateTime @db.Timestamptz()
endDate DateTime @db.Timestamptz()
soloProjectDeadline DateTime @db.Timestamptz()
certificateIssueDate DateTime @db.Timestamptz()
showcasePublishDate DateTime? @db.Timestamptz()
createdAt DateTime @default(now()) @db.Timestamptz()
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -127,6 +129,7 @@ model VoyageStatus {
voyageTeams VoyageTeam[]
voyageTeamMembers VoyageTeamMember[]
Voyage Voyage[]
}

model Tier {
Expand Down
14 changes: 14 additions & 0 deletions prisma/seed/data/voyage-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@ export default [
description:
"member has dropped from the voyage or the team has disbanded",
},
{
name: "Inactive",
description:
"member is inactive or the team is inactive. " +
"If a voyage status is inactive, member will still be able to access it",
},
{
name: "Upcoming",
description: "Upcoming voyage",
},
{
name: "Locked",
description: "Voyage is locked, read only mode",
},
];
23 changes: 0 additions & 23 deletions prisma/seed/data/voyages.ts

This file was deleted.

4 changes: 3 additions & 1 deletion prisma/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import * as process from "process";
import { populateTeamResourcesAndProjectIdeas } from "./resources-project-ideas";
import { populateTables } from "./tables";
import { populateFormsAndResponses } from "./forms";
import { populateVoyageTeams } from "./voyageTeams";
import { populateVoyageTeams } from "./voyage-teams";
import { populateUsers } from "./users";
import { populateSprints } from "./sprints";
import { populateMeetings } from "./meetings";
import { populateSoloProjects } from "./solo-project";
import { populateVoyageApplications } from "./voyage-app";
import { populateChecklists } from "./checklist";
import { populateVoyages } from "./voyage";

const prisma = new PrismaClient();

Expand Down Expand Up @@ -38,6 +39,7 @@ const deleteAllTables = async () => {
try {
await deleteAllTables();
await populateTables(); // tables with no relations
await populateVoyages();
await populateUsers();
await populateSprints();
await populateVoyageTeams();
Expand Down
2 changes: 0 additions & 2 deletions prisma/seed/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import VoyageRoles from "./data/voyage-roles";
import VoyageStatus from "./data/voyage-status";
import TechStackCategories from "./data/tech-stack-categories";

import Voyages from "./data/voyages";
import FeatureCategories from "./data/feature-categories";

import FormTypes from "./data/form-types";
Expand All @@ -27,7 +26,6 @@ export const populateTables = async () => {
await populateTable("voyageRole", VoyageRoles);
await populateTable("voyageStatus", VoyageStatus);
await populateTable("techStackCategory", TechStackCategories);
await populateTable("voyage", Voyages);
await populateTable("featureCategory", FeatureCategories);
await populateTable("formType", FormTypes);
await populateTable("inputType", InputTypes);
Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions prisma/seed/voyage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export const populateVoyages = async () => {
await prisma.voyage.create({
data: {
number: "47",
status: {
connect: {
name: "Active",
},
},
startDate: new Date("2024-01-08"),
endDate: new Date("2024-02-18"),
soloProjectDeadline: new Date("2023-12-31"),
certificateIssueDate: new Date("2024-02-25"),
},
});
await prisma.voyage.create({
data: {
number: "48",
status: {
connect: {
name: "Upcoming",
},
},
startDate: new Date("2024-03-05"),
endDate: new Date("2024-04-14"),
soloProjectDeadline: new Date("2024-02-25"),
certificateIssueDate: new Date("2024-04-21"),
},
});
await prisma.voyage.create({
data: {
number: "49",
status: {
connect: {
name: "Upcoming",
},
},
startDate: new Date("2024-05-06"),
endDate: new Date("2024-06-16"),
soloProjectDeadline: new Date("2024-04-28"),
certificateIssueDate: new Date("2024-06-23"),
},
});
};
8 changes: 8 additions & 0 deletions src/users/users.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ class VoyageTeamWithoutMember {
updatedAt: Date;
}

class Voyage {
@ApiProperty()
status: VoyageStatus;
}

class VoyageTeam {
@ApiProperty({ example: "v47-tier2-team-4" })
name: string;

@ApiProperty()
voyage: Voyage;
}

class UserVoyageTeam {
Expand Down
13 changes: 13 additions & 0 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class UsersService {
});
}

// /me endpoint, user's own profile/data
getPrivateUserProfile(userId: string) {
return this.prisma.user.findUnique({
where: {
Expand All @@ -68,12 +69,24 @@ export class UsersService {
countryCode: true,
timezone: true,
voyageTeamMembers: {
orderBy: {
voyageTeamId: "desc",
},
select: {
id: true,
voyageTeamId: true,
voyageTeam: {
select: {
name: true,
voyage: {
select: {
status: {
select: {
name: true,
},
},
},
},
},
},
voyageRole: {
Expand Down

0 comments on commit 8d6fbc1

Please sign in to comment.