-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aplication controller, ui to submit application
- Loading branch information
Showing
18 changed files
with
254 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface ApplicationModel { | ||
cv: File; | ||
letter: string; | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/resources/applications/applications.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ApplicationsController } from './applications.controller'; | ||
import { ApplicationsService } from './applications.service'; | ||
|
||
describe('ApplicationsController', () => { | ||
let controller: ApplicationsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [ApplicationsController], | ||
providers: [ApplicationsService], | ||
}).compile(); | ||
|
||
controller = module.get<ApplicationsController>(ApplicationsController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
backend/src/resources/applications/applications.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Ip, | ||
Param, | ||
Patch, | ||
Post, | ||
UploadedFile, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { ApplicationsService } from './applications.service'; | ||
import { CreateApplicationDto } from './dto/create-application.dto'; | ||
import { UpdateApplicationDto } from './dto/update-application.dto'; | ||
import { FileInterceptor } from '@nestjs/platform-express'; | ||
|
||
@Controller('applications') | ||
export class ApplicationsController { | ||
constructor(private readonly applicationsService: ApplicationsService) {} | ||
|
||
@Post() | ||
@UseInterceptors(FileInterceptor('cv')) | ||
create( | ||
@Body() createApplicationDto: CreateApplicationDto, | ||
@UploadedFile() cv: Express.Multer.File, | ||
@Ip() ip: string, | ||
) { | ||
return this.applicationsService.saveApplication({ | ||
...createApplicationDto, | ||
cv, | ||
ip, | ||
}); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.applicationsService.findAll(); | ||
} | ||
|
||
@Get('canSubmit') | ||
public canSubmit(@Ip() ip: string) { | ||
return this.applicationsService.allowedToSubmit(ip); | ||
} | ||
|
||
@Patch(':id') | ||
update( | ||
@Param('id') id: string, | ||
@Body() updateApplicationDto: UpdateApplicationDto, | ||
) { | ||
return this.applicationsService.update(+id, updateApplicationDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
return this.applicationsService.remove(+id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ApplicationsService } from './applications.service'; | ||
import { ApplicationsController } from './applications.controller'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { ApplicationEntity } from './entities/application.entity'; | ||
import { S3Service } from '../../services/s3.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([ApplicationEntity])], | ||
controllers: [ApplicationsController], | ||
providers: [ApplicationsService, S3Service], | ||
}) | ||
export class ApplicationsModule {} |
18 changes: 18 additions & 0 deletions
18
backend/src/resources/applications/applications.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ApplicationsService } from './applications.service'; | ||
|
||
describe('ApplicationsService', () => { | ||
let service: ApplicationsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ApplicationsService], | ||
}).compile(); | ||
|
||
service = module.get<ApplicationsService>(ApplicationsService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
backend/src/resources/applications/applications.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateApplicationDto } from './dto/create-application.dto'; | ||
import { UpdateApplicationDto } from './dto/update-application.dto'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { ApplicationEntity } from './entities/application.entity'; | ||
import { S3Service } from '../../services/s3.service'; | ||
|
||
@Injectable() | ||
export class ApplicationsService { | ||
constructor( | ||
@InjectRepository(ApplicationEntity) | ||
private readonly applicationRepository: Repository<ApplicationEntity>, | ||
private readonly s3Service: S3Service, | ||
) {} | ||
|
||
public async saveApplication( | ||
createApplicationDto: CreateApplicationDto, | ||
): Promise<boolean> { | ||
const cvUrl = await this.s3Service.uploadFile(createApplicationDto.cv); | ||
const applicationToSave = this.applicationRepository.create({ | ||
...createApplicationDto, | ||
cvUrl, | ||
}); | ||
const application = | ||
await this.applicationRepository.save(applicationToSave); | ||
return !!application.id; | ||
} | ||
|
||
findAll() { | ||
return `This action returns all applications`; | ||
} | ||
|
||
public async allowedToSubmit(ip: string): Promise<boolean> { | ||
const record = await this.applicationRepository.findOneBy({ ip }); | ||
return !Boolean(record); | ||
} | ||
|
||
update(id: number, updateApplicationDto: UpdateApplicationDto) { | ||
return `This action updates a #${id} application`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} application`; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
backend/src/resources/applications/dto/create-application.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class CreateApplicationDto { | ||
cv: Express.Multer.File; | ||
letter: string; | ||
ip?: string; | ||
} |
4 changes: 4 additions & 0 deletions
4
backend/src/resources/applications/dto/update-application.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreateApplicationDto } from './create-application.dto'; | ||
|
||
export class UpdateApplicationDto extends PartialType(CreateApplicationDto) {} |
13 changes: 13 additions & 0 deletions
13
backend/src/resources/applications/entities/application.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
@Entity({ name: 'applications' }) | ||
export class ApplicationEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
@Column({ length: 255, nullable: false }) | ||
ip: string; | ||
@Column({ length: 255, nullable: false }) | ||
cvUrl: string; | ||
@Column({ type: 'varchar', nullable: false }) | ||
letter: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface ApplicationModel { | ||
cv: File | null; | ||
letter: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,49 @@ | ||
// import styles from './Details.module.scss'; | ||
import {useParams} from 'react-router-dom'; | ||
import {useAuth0} from "@auth0/auth0-react"; | ||
import {useEffect} from "react"; | ||
import {useLocation, useParams} from 'react-router-dom'; | ||
import Upload from "../../components/upload/Upload.tsx"; | ||
import {ChangeEvent, useEffect, useState} from "react"; | ||
import {TextareaAutosize} from "@mui/material"; | ||
import {ApplicationModel} from "../../models/application.model.ts"; | ||
import {hasSubmitted, submitApplication} from "../../services/api/application/application.service.ts"; | ||
// import {useAsyncErrorBoundary} from "../errors/asyncErrorBoundary/UseAsyncErrorBoundary.ts"; | ||
|
||
export const Details = () => { | ||
const {isAuthenticated} = useAuth0() | ||
const [form, setForm] = useState<ApplicationModel>({cv: null, letter: ''}) | ||
const [canSubmit, setCanSubmit] = useState<boolean>(true) | ||
useEffect(() => { | ||
console.log(isAuthenticated) | ||
}, [isAuthenticated]); | ||
// const catchAsync = useAsyncErrorBoundary(); | ||
hasSubmitted().then(res => setCanSubmit(res.data)).catch(console.log) | ||
}, []) | ||
const {id} = useParams(); | ||
return <div>{id}</div> | ||
const {state: job} = useLocation(); | ||
const sendApplication = () => { | ||
if (form.cv && form.letter.length) { | ||
submitApplication(form).then(() => setCanSubmit(false)).catch(console.log) | ||
} | ||
} | ||
|
||
const onUploadChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
const target = event.target; | ||
setForm({...form, cv: target.files![0]}) | ||
} | ||
|
||
const onCoverLetterChange = (event: ChangeEvent<HTMLTextAreaElement>) => { | ||
setForm({...form, letter: event.target.value}) | ||
} | ||
return <div className={"abt-center"}> | ||
<div>{job.companyName}</div> | ||
<div>{job.jobTitle}</div> | ||
<div>{job.description}</div> | ||
<div>Salary: {job.fork}</div> | ||
<div>Views: {job.views}</div> | ||
<div>Applications {job.applications_sent}</div> | ||
<div>create date {job.created_at}</div> | ||
<TextareaAutosize onChange={onCoverLetterChange}></TextareaAutosize> | ||
<Upload onChange={onUploadChange}></Upload> | ||
{canSubmit ? | ||
<button onClick={sendApplication}>Apply to | ||
possition button | ||
</button> | ||
: | ||
<div>You already sent an application</div> | ||
} | ||
</div> | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
frontend/src/services/api/application/application.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {apiService} from "../api-base.service.ts"; | ||
import {ApplicationModel} from "../../../models/application.model.ts"; | ||
|
||
export const submitApplication = async (application: ApplicationModel) => { | ||
return await apiService.instance.post<ApplicationModel>('applications', application, {headers: {"Content-Type": "multipart/form-data"}}); | ||
} | ||
|
||
export const hasSubmitted = async () => { | ||
return await apiService.instance.get<boolean>('applications/canSubmit') | ||
} |