Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions apps/backend/src/application/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { PrismaService } from 'nestjs-prisma';
import { ApplicationPeriodService } from 'src/application-period/application-period.service';
import { PaginationDto } from 'src/dto/pagination.dto';

import { DefaultArgs } from '@prisma/client/runtime/library';
import { CreateApplicationDto } from './dto/create-application.dto';
import { UpdateApplicationDto } from './dto/update-application.dto';
import { DefaultArgs } from '@prisma/client/runtime/library';

@Injectable()
export class ApplicationService {
Expand All @@ -32,10 +32,19 @@ export class ApplicationService {
if (new Date(applicationPeriod.applicationPeriodEndAt) < new Date()) {
throw new BadRequestException('A jelentkezési időszak lejárt');
}
const currentUser = await this.prisma.user.findUnique({
where: { authSchId: user.authSchId, NOT: { profilePicture: null } },
const currentUser = await this.prisma.user.findFirstOrThrow({
where: {
authSchId: user.authSchId,
},
include: {
profilePicture: {
select: {
status: true,
},
},
},
});
if (!currentUser) {
if (!currentUser || !currentUser.profilePicture) {
throw new NotAcceptableException('Hiányos profil');
}
return await this.prisma.application.create({
Expand All @@ -45,6 +54,12 @@ export class ApplicationService {
authSchId: user.authSchId,
},
},
status:
currentUser.profilePicture.status === 'PENDING'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ezt egy fv visszaadhatná, 2 ternary egymásban már elég olvashatatlan

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String helyett jobb lenne használni az ApplicationStatus enumot

? 'SUBMITTED'
: currentUser.profilePicture.status === 'ACCEPTED'
? 'ACCEPTED'
: 'REJECTED',
applicationPeriod: {
connect: {
id: createApplicationDto.applicationPeriodId,
Expand Down Expand Up @@ -212,12 +227,13 @@ export class ApplicationService {
if (new Date(applicationPeriod.applicationPeriodEndAt) < new Date()) {
throw new BadRequestException('A jelentkezési időszak lejárt');
}
return await this.prisma.application.delete({
return this.prisma.application.delete({
where: {
id,
},
});
}

throw new ForbiddenException('Nem törölheted mások jelentkezését');
}

Expand Down
13 changes: 5 additions & 8 deletions apps/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
NotFoundException,
UnauthorizedException,
} from '@nestjs/common';
import { Prisma, ProfilePictureStatus, User } from '@prisma/client';
import { ApplicationStatus, Prisma, ProfilePictureStatus, User } from '@prisma/client';
import { PrismaService } from 'nestjs-prisma';
import { optimizeImage } from 'src/util';

Expand Down Expand Up @@ -61,20 +61,17 @@ export class UserService {
async setProfilePictureStatus(id: string, status: any) {
try {
const transactionResult = await this.prisma.$transaction(async (tx) => {
if (status !== ProfilePictureStatus.PENDING) {
await this.applicationService.setActiveApplicationsStatus(id, status, tx);
let appStatus = status;
if (status === 'PENDING') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String helyett jobb lenne használni az ApplicationStatus enumot

appStatus = ApplicationStatus.SUBMITTED;
}
await this.applicationService.setActiveApplicationsStatus(id, appStatus, tx);
return tx.profilePicture.update({
where: { userId: id },
data: { status: status },
});
});
const user = await this.prisma.user.findUnique({ where: { authSchId: id } });
/*await this.emailService.sendEmail(
user.email,
'[SCHBody] A profilképed állapota módosult',
'Amennyiben volt aktív, elbírálás alatt álló jelentkezésed, annak státusza megváltozott. Kérjük, hogy ellenőrizd a jelentkezésed státuszát a SCHBody felületén.'
);*/
if (status !== ProfilePictureStatus.PENDING) {
await this.emailService.sendProfilePictureStatusChangeEmail(user.nickName, user.email, status, true);
}
Expand Down