Skip to content

Commit

Permalink
feat: introduced isFeatured option in member, team, project, pl-events
Browse files Browse the repository at this point in the history
  - added new api to fetch featured member, team, project, events
  • Loading branch information
navneethkrish committed Aug 19, 2024
1 parent d54ef20 commit f5dba43
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .forestadmin-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,22 @@
"type": "Number",
"validations": []
},
{
"defaultValue": false,
"enums": null,
"field": "isFeatured",
"integration": null,
"inverseOf": null,
"isFilterable": true,
"isPrimaryKey": false,
"isReadOnly": false,
"isRequired": false,
"isSortable": true,
"isVirtual": false,
"reference": null,
"type": "Boolean",
"validations": []
},
{
"defaultValue": null,
"enums": null,
Expand Down Expand Up @@ -3187,6 +3203,22 @@
"type": "Number",
"validations": []
},
{
"defaultValue": false,
"enums": null,
"field": "isFeatured",
"integration": null,
"inverseOf": null,
"isFilterable": true,
"isPrimaryKey": false,
"isReadOnly": false,
"isRequired": false,
"isSortable": true,
"isVirtual": false,
"reference": null,
"type": "Boolean",
"validations": []
},
{
"defaultValue": null,
"enums": null,
Expand Down Expand Up @@ -4010,6 +4042,22 @@
{"type": "is present", "message": "Failed validation rule: 'Present'"}
]
},
{
"defaultValue": false,
"enums": null,
"field": "isFeatured",
"integration": null,
"inverseOf": null,
"isFilterable": true,
"isPrimaryKey": false,
"isReadOnly": false,
"isRequired": false,
"isSortable": true,
"isVirtual": false,
"reference": null,
"type": "Boolean",
"validations": []
},
{
"defaultValue": null,
"enums": null,
Expand Down Expand Up @@ -4857,6 +4905,22 @@
"type": "Number",
"validations": []
},
{
"defaultValue": false,
"enums": null,
"field": "isFeatured",
"integration": null,
"inverseOf": null,
"isFilterable": true,
"isPrimaryKey": false,
"isReadOnly": false,
"isRequired": false,
"isSortable": true,
"isVirtual": false,
"reference": null,
"type": "Boolean",
"validations": []
},
{
"defaultValue": null,
"enums": null,
Expand Down
1 change: 1 addition & 0 deletions apps/web-api/prisma/fixtures/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const membersFactory = Factory.define<Omit<Member, 'id'>>(
plnFriend: faker.datatype.boolean(),
airtableRecId: `airtable-rec-id-${sequence}`,
externalId: null,
isFeatured: faker.datatype.boolean(),
createdAt: faker.date.past(),
approvedAt: faker.date.past(),
plnStartDate: faker.date.past(),
Expand Down
1 change: 1 addition & 0 deletions apps/web-api/prisma/fixtures/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const ProjectFactory = Factory.define<Omit<Project, 'id'>>(
readMe: faker.lorem.paragraph(),
createdBy: '',
maintainingTeamUid: '',
isFeatured: faker.datatype.boolean(),
projectLinks: [{
name: faker.company.name(),
url: faker.internet.url()
Expand Down
1 change: 1 addition & 0 deletions apps/web-api/prisma/fixtures/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const teamsFactory = Factory.define<Omit<Team, 'id'>>(
officeHours: faker.name.firstName(),
linkedinHandler: faker.name.firstName(),
telegramHandler: faker.name.firstName(),
isFeatured: faker.datatype.boolean(),
shortDescription: faker.helpers.arrayElement([
null,
faker.lorem.sentence(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "Member" ADD COLUMN "isFeatured" BOOLEAN DEFAULT false;

-- AlterTable
ALTER TABLE "PLEvent" ADD COLUMN "isFeatured" BOOLEAN DEFAULT false;

-- AlterTable
ALTER TABLE "Project" ADD COLUMN "isFeatured" BOOLEAN DEFAULT false;

-- AlterTable
ALTER TABLE "Team" ADD COLUMN "isFeatured" BOOLEAN DEFAULT false;
6 changes: 6 additions & 0 deletions apps/web-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ model Team {
shortDescription String?
longDescription String?
plnFriend Boolean @default(false)
isFeatured Boolean? @default(false)
airtableRecId String? @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -68,6 +69,7 @@ model Member {
airtableRecId String? @unique
externalId String? @unique
openToWork Boolean? @default(false)
isFeatured Boolean? @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
approvedAt DateTime @default(now())
Expand Down Expand Up @@ -330,6 +332,7 @@ model Project {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
isDeleted Boolean @default(false)
isFeatured Boolean? @default(false)
projectFocusAreas ProjectFocusArea[]
contributions ProjectContribution[]
}
Expand All @@ -348,6 +351,7 @@ model PLEvent {
description String?
shortDescription String?
websiteURL String?
isFeatured Boolean? @default(false)
location String
slugURL String @unique
resources Json[]
Expand Down Expand Up @@ -495,3 +499,5 @@ model MemberFeedback {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}


4 changes: 3 additions & 1 deletion apps/web-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { EmptyStringToNullInterceptor } from './interceptors/empty-string-to-nul
import { OfficeHoursModule } from './office-hours/office-hours.module';
import { MemberFollowUpsModule } from './member-follow-ups/member-follow-ups.module';
import { MemberFeedbacksModule } from './member-feedbacks/member-feedbacks.module';
import { HomeModule } from './home/home.module';

@Module({
controllers: [AppController],
Expand Down Expand Up @@ -90,7 +91,8 @@ import { MemberFeedbacksModule } from './member-feedbacks/member-feedbacks.modul
PLEventsModule,
OfficeHoursModule,
MemberFollowUpsModule,
MemberFeedbacksModule
MemberFeedbacksModule,
HomeModule
],
providers: [
{
Expand Down
18 changes: 18 additions & 0 deletions apps/web-api/src/home/home.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Controller, Req } from '@nestjs/common';
import { Api, initNestServer } from '@ts-rest/nest';
import { Request } from 'express';
import { apiHome } from 'libs/contracts/src/lib/contract-home';
import { HomeService } from './home.service';

const server = initNestServer(apiHome);
type RouteShape = typeof server.routeShapes;

@Controller()
export class HomeController {
constructor(private homeService: HomeService) {}

@Api(server.route.getAllFeaturedData)
async getAllFeaturedData(@Req() request: Request) {
return await this.homeService.fetchAllFeaturedData();
}
}
24 changes: 24 additions & 0 deletions apps/web-api/src/home/home.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Module } from '@nestjs/common';
import { HomeController } from './home.controller';
import { HomeService } from './home.service';
import { MembersModule } from '../members/members.module';
import { TeamsModule } from '../teams/teams.module';
import { ProjectsModule} from '../projects/projects.module';
import { PLEventsModule } from '../pl-events/pl-events.module';

@Module({
controllers: [HomeController],
providers: [
HomeService
],
imports:[
MembersModule,
TeamsModule,
ProjectsModule,
PLEventsModule
],
exports: [
HomeService
]
})
export class HomeModule {}
33 changes: 33 additions & 0 deletions apps/web-api/src/home/home.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { LogService } from '../shared/log.service';
import { MembersService } from '../members/members.service';
import { TeamsService } from '../teams/teams.service';
import { PLEventsService } from '../pl-events/pl-events.service';
import { ProjectsService } from '../projects/projects.service';

@Injectable()
export class HomeService {
constructor(
private logger: LogService,
private memberService: MembersService,
private teamsService: TeamsService,
private plEventsService: PLEventsService,
private projectsService: ProjectsService
) {}

async fetchAllFeaturedData() {
try {
const filter = { where : { isFeatured: true }}
return {
members: await this.memberService.findAll(filter),
teams: await this.teamsService.findAll(filter),
events: await this.plEventsService.getPLEvents(filter),
projects: await this.projectsService.getProjects(filter)
};
}
catch (error) {
this.logger.error(error);
throw new InternalServerErrorException('Failed to fetch featured data');
}
}
}
1 change: 1 addition & 0 deletions apps/web-api/src/members/__mocks__/members.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function createMember({ amount }: TestFactorySeederParams) {
moreDetails: 'moreDetails',
officeHours: 'officeHours',
plnFriend: true,
isFeatured: false,
airtableRecId: `airtable-rec-id-${sequence}`,
externalId: `external-${sequence}`,
plnStartDate: new Date(),
Expand Down
1 change: 1 addition & 0 deletions apps/web-api/src/pl-events/pl-events.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MembersModule } from '../members/members.module';
providers: [
PLEventsService,
],
exports: [PLEventsService],
imports:[MembersModule]
})
export class PLEventsModule {}
12 changes: 12 additions & 0 deletions apps/web-api/src/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ export class ProjectsService {
isDeleted: false
};
queryOptions.include = {
contributions: {
select: {
uid: true,
member: {
select: {
uid: true,
name: true,
image: true
}
}
}
},
maintainingTeam: { select: { uid: true, name: true, logo: true }},
creator: { select: { uid: true, name: true, image: true }},
logo: true
Expand Down
1 change: 1 addition & 0 deletions apps/web-api/src/teams/__mocks__/teams.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function createTeam({ amount }: TestFactorySeederParams) {
shortDescription: faker.lorem.sentence(),
longDescription: faker.lorem.paragraph(),
plnFriend: true,
isFeatured: true,
airtableRecId: `airtable-rec-id-${sequence}`,
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
16 changes: 16 additions & 0 deletions libs/contracts/src/lib/contract-home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { initContract } from '@ts-rest/core';
import { getAPIVersionAsPath } from '../utils/versioned-path';

const contract = initContract();

export const apiHome = contract.router({
getAllFeaturedData: {
method: 'GET',
path: `${getAPIVersionAsPath('1')}/home/featured/all`,
query: contract.query,
responses: {
200: contract.response<unknown>()
},
summary: 'Get all featured members, projects, teams and events',
}
});
1 change: 1 addition & 0 deletions libs/contracts/src/schema/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const MemberSchema = z.object({
officeHours: z.string().nullish(),
airtableRecId: z.string().nullish(),
plnFriend: z.boolean(),
isFeatured: z.boolean().nullish(),
createdAt: z.string(),
updatedAt: z.string(),
locationUid: z.string(),
Expand Down
1 change: 1 addition & 0 deletions libs/contracts/src/schema/pl-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const PLEventSchema = z.object({
eventsCount: z.number().int(),
logoUid: z.string().nullish(),
bannerUid: z.string().nullish(),
isFeatured: z.boolean().nullish(),
description: z.string().optional(),
shortDescription: z.string().optional(),
websiteURL: z.string().url().optional(),
Expand Down
1 change: 1 addition & 0 deletions libs/contracts/src/schema/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ProjectSchema = z.object({
tagline: z.string(),
score: z.number().optional().nullable(),
description: z.string(),
isFeatured: z.boolean().nullish(),
contactEmail: z.string().email().nullish().transform((email)=> {
return email && email.toLowerCase()
}),
Expand Down
1 change: 1 addition & 0 deletions libs/contracts/src/schema/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const TeamSchema = z.object({
twitterHandler: z.string().nullish(),
shortDescription: z.string().nullish(),
longDescription: z.string().nullish(),
isFeatured: z.boolean().nullish(),
plnFriend: z.boolean(),
startDate: z.date().or(z.string()).nullish(),
endDate: z.date().or(z.string()).nullish(),
Expand Down

0 comments on commit f5dba43

Please sign in to comment.