Skip to content

Commit 75e1880

Browse files
authored
Merge pull request #625 from dump-hr/lukazuljevic/618-sponzori-sami-unose-fly-talk-podatke
Lukazuljevic/618 sponzori sami unose fly talk podatke
2 parents a39c17a + ba4cb27 commit 75e1880

File tree

17 files changed

+538
-10
lines changed

17 files changed

+538
-10
lines changed

apps/admin/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
26+
tsconfig.tsbuildinfo
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { CompanyDto as CompanyAdminDto } from '@ddays-app/types';
2+
import { QueryOptions, useQuery } from 'react-query';
3+
4+
import { api } from '..';
5+
6+
const companyGetAllAdmin = async () => {
7+
return await api.get<never, CompanyAdminDto[]>('/company/all-for-admin');
8+
};
9+
10+
export const useCompanyGetAllAdmin = (
11+
options?: QueryOptions<CompanyAdminDto[]>,
12+
) => {
13+
return useQuery(['company', 'admin'], companyGetAllAdmin, options);
14+
};

apps/admin/src/pages/CompanyPage/CompanyPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { TableDashboard } from '../../components/TableDashboard';
2-
import { useCompanyGetAllPublic } from '../../api/company/useCompanyGetAllPublic';
32
import { CompanyForm } from '../../forms/CompanyForm';
43
import { useCompanyRemove } from '../../api/company/useCompanyRemove';
54
import toast from 'react-hot-toast';
5+
import { useCompanyGetAllAdmin } from '../../api/company/useCompanyGetAllAdmin';
66

77
export const CompanyPage = () => {
8-
const { data: companies, refetch } = useCompanyGetAllPublic();
8+
const { data: companies, refetch } = useCompanyGetAllAdmin();
99
const removeCompany = useCompanyRemove();
1010

1111
const handleDelete = async (ids: number[]) => {

apps/admin/tsconfig.tsbuildinfo

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "public"."Company" ADD COLUMN "flyTalkHolders" JSONB;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `flyTalkHolders` on the `Company` table. All the data in the column will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "public"."Company" DROP COLUMN "flyTalkHolders",
9+
ADD COLUMN "flytalkHolders" JSONB,
10+
ADD COLUMN "flytalkParticipation" BOOLEAN NOT NULL DEFAULT false;

apps/api/prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ model Company {
9797
notes String[]
9898
campfireParticipation Boolean @default(false)
9999
campfireSpeakers String[]
100+
flytalkParticipation Boolean @default(false)
101+
flytalkHolders Json?
100102
codeId Int?
101103
booth Booth?
102104
code Code? @relation(fields: [codeId], references: [id], onDelete: NoAction, onUpdate: NoAction)

apps/api/src/company/company.controller.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
2+
CompanyAdminDto,
23
CompanyDto,
34
CompanyModifyDescriptionDto,
45
CompanyModifyDto,
6+
CompanyModifyFlyTalkHoldersDto,
57
CompanyPublicDto,
68
FloorPlanCompanyDto,
79
} from '@ddays-app/types';
@@ -47,6 +49,12 @@ export class CompanyController {
4749
return await this.companyService.getAllPublic();
4850
}
4951

52+
@UseGuards(AdminGuard)
53+
@Get('all-for-admin')
54+
async getAllForAdmin(): Promise<CompanyAdminDto[]> {
55+
return await this.companyService.getAllForAdmin();
56+
}
57+
5058
@UseGuards(UserGuard)
5159
@Get('recommended')
5260
async getRecommended(
@@ -172,6 +180,16 @@ export class CompanyController {
172180
return await this.companyService.updateAccreditation(user.id, data);
173181
}
174182

183+
@UseGuards(SponsorGuard)
184+
@ApiBearerAuth()
185+
@Patch('/flytalk-holders')
186+
async updateFlyTalkHolders(
187+
@Req() { user }: AuthenticatedRequest,
188+
@Body() data: CompanyModifyFlyTalkHoldersDto,
189+
) {
190+
return await this.companyService.updateFlyTalkHolders(user.id, data);
191+
}
192+
175193
@UseGuards(SponsorGuard)
176194
@ApiBearerAuth()
177195
@ApiConsumes('multipart/form-data')

apps/api/src/company/company.service.ts

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {
2+
CompanyAdminDto,
23
CompanyDto,
34
CompanyModifyDescriptionDto,
45
CompanyModifyDto,
6+
CompanyModifyFlyTalkHoldersDto,
57
CompanyPublicDto,
68
FloorPlanCompanyDto,
79
} from '@ddays-app/types';
810
import { UserToCompanyDto } from '@ddays-app/types/src/dto/user';
911
import { Injectable, NotFoundException } from '@nestjs/common';
12+
import { InputJsonValue } from '@prisma/client/runtime/library';
1013
import { BlobService } from 'src/blob/blob.service';
1114
import { InterestService } from 'src/interest/interest.service';
1215
import { PrismaService } from 'src/prisma.service';
@@ -60,6 +63,43 @@ export class CompanyService {
6063
}));
6164
}
6265

66+
async getAllForAdmin(): Promise<CompanyAdminDto[]> {
67+
const companies = await this.prisma.company.findMany({
68+
select: {
69+
id: true,
70+
category: true,
71+
name: true,
72+
username: true,
73+
password: true,
74+
description: true,
75+
opportunitiesDescription: true,
76+
websiteUrl: true,
77+
instagramUrl: true,
78+
linkedinUrl: true,
79+
logoImage: true,
80+
landingImage: true,
81+
landingImageCompanyCulture: true,
82+
bookOfStandards: true,
83+
video: true,
84+
peopleForAccreditation: true,
85+
swagBag: true,
86+
swagBagNumber: true,
87+
boothPlan: true,
88+
equipment: true,
89+
notes: true,
90+
codeId: true,
91+
flytalkParticipation: true,
92+
flytalkHolders: true,
93+
},
94+
orderBy: { name: 'asc' },
95+
});
96+
97+
return companies.map((company) => ({
98+
...company,
99+
flytalkHolders: (company.flytalkHolders as unknown as JSON) || null,
100+
}));
101+
}
102+
63103
async getTopRatedCompanies(): Promise<CompanyPublicDto[]> {
64104
const companies = await this.prisma.company.findMany({
65105
where: {
@@ -104,6 +144,7 @@ export class CompanyService {
104144

105145
return topRated.map(({ ...company }) => ({
106146
...company,
147+
flytalkHolders: (company.flytalkHolders as unknown as JSON) || null,
107148
}));
108149
}
109150

@@ -139,6 +180,7 @@ export class CompanyService {
139180
...foundCompany,
140181
booth: foundCompany.booth?.name || null,
141182
boothId: foundCompany.booth?.id || null,
183+
flytalkHolders: (foundCompany.flytalkHolders as unknown as JSON) || null,
142184
interests,
143185
};
144186
}
@@ -338,7 +380,30 @@ export class CompanyService {
338380
},
339381
});
340382

341-
return updatedCompany;
383+
return {
384+
...updatedCompany,
385+
flytalkHolders:
386+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
387+
};
388+
}
389+
390+
async updateFlyTalkHolders(
391+
companyId: number,
392+
data: CompanyModifyFlyTalkHoldersDto,
393+
): Promise<CompanyPublicDto> {
394+
const updatedCompany = await this.prisma.company.update({
395+
where: { id: companyId },
396+
data: {
397+
flytalkParticipation: data.flytalkParticipation,
398+
flytalkHolders: data.flytalkHolders as unknown as InputJsonValue,
399+
},
400+
});
401+
402+
return {
403+
...updatedCompany,
404+
flytalkHolders:
405+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
406+
};
342407
}
343408

344409
async updateAccreditation(
@@ -352,7 +417,11 @@ export class CompanyService {
352417
},
353418
});
354419

355-
return updatedCompany;
420+
return {
421+
...updatedCompany,
422+
flytalkHolders:
423+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
424+
};
356425
}
357426

358427
async updateLandingImage(
@@ -370,7 +439,11 @@ export class CompanyService {
370439
data: { landingImage },
371440
});
372441

373-
return updatedCompany;
442+
return {
443+
...updatedCompany,
444+
flytalkHolders:
445+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
446+
};
374447
}
375448

376449
async updateLandingImageCompanyCulture(
@@ -388,7 +461,11 @@ export class CompanyService {
388461
data: { landingImageCompanyCulture },
389462
});
390463

391-
return updatedCompany;
464+
return {
465+
...updatedCompany,
466+
flytalkHolders:
467+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
468+
};
392469
}
393470

394471
async updateBookOfStandards(
@@ -406,7 +483,11 @@ export class CompanyService {
406483
data: { bookOfStandards },
407484
});
408485

409-
return updatedCompany;
486+
return {
487+
...updatedCompany,
488+
flytalkHolders:
489+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
490+
};
410491
}
411492

412493
async updateLogoImage(
@@ -424,7 +505,11 @@ export class CompanyService {
424505
data: { logoImage },
425506
});
426507

427-
return updatedCompany;
508+
return {
509+
...updatedCompany,
510+
flytalkHolders:
511+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
512+
};
428513
}
429514

430515
async updateVideo(
@@ -442,7 +527,11 @@ export class CompanyService {
442527
data: { video },
443528
});
444529

445-
return updatedCompany;
530+
return {
531+
...updatedCompany,
532+
flytalkHolders:
533+
(updatedCompany.flytalkHolders as unknown as JSON) || null,
534+
};
446535
}
447536

448537
async getFloorPlan(): Promise<FloorPlanCompanyDto[]> {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { CompanyModifyFlyTalkHoldersDto } from '@ddays-app/types';
2+
import toast from 'react-hot-toast';
3+
import { useMutation, useQueryClient } from 'react-query';
4+
5+
import { api } from '..';
6+
7+
const companyUpdateFlyTalkHolders = async (
8+
dto: CompanyModifyFlyTalkHoldersDto,
9+
) => {
10+
return await api.patch<CompanyModifyFlyTalkHoldersDto, never>(
11+
'/company/flytalk-holders',
12+
dto,
13+
);
14+
};
15+
16+
export const useCompanyUpdateFlyTalkHolders = () => {
17+
const queryClient = useQueryClient();
18+
19+
return useMutation(companyUpdateFlyTalkHolders, {
20+
onSuccess: () => {
21+
queryClient.invalidateQueries(['company', 'current']);
22+
23+
toast.success('FlyTalk holders podaci uspješno spremljeni');
24+
},
25+
onError: (error: string) => {
26+
toast.error(error);
27+
},
28+
});
29+
};

0 commit comments

Comments
 (0)