mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-16 17:51:43 +10:00
Changes
This commit is contained in:
@ -53,7 +53,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.17.10",
|
||||
"@reactive-resume/schema": "workspace:*",
|
||||
"@tailwindcss/typography": "^0.5.2",
|
||||
"@types/downloadjs": "^1.4.3",
|
||||
"@types/lodash": "^4.14.182",
|
||||
|
||||
7585
pnpm-lock.yaml
generated
7585
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,6 @@
|
||||
"lint": "eslint --fix --ext .ts ./src"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.81.0",
|
||||
"@nestjs/axios": "^0.0.7",
|
||||
"@nestjs/common": "^8.4.4",
|
||||
"@nestjs/config": "^2.0.0",
|
||||
@ -53,7 +52,6 @@
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^8.2.5",
|
||||
"@nestjs/schematics": "^8.0.10",
|
||||
"@reactive-resume/schema": "workspace:*",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/cookie-parser": "^1.4.3",
|
||||
"@types/express": "^4.17.13",
|
||||
|
||||
@ -7,7 +7,6 @@ import authConfig from './auth.config';
|
||||
import databaseConfig from './database.config';
|
||||
import googleConfig from './google.config';
|
||||
import sendgridConfig from './sendgrid.config';
|
||||
import storageConfig from './storage.config';
|
||||
|
||||
const validationSchema = Joi.object({
|
||||
// App
|
||||
@ -41,20 +40,12 @@ const validationSchema = Joi.object({
|
||||
SENDGRID_FORGOT_PASSWORD_TEMPLATE_ID: Joi.string().allow(''),
|
||||
SENDGRID_FROM_NAME: Joi.string().allow(''),
|
||||
SENDGRID_FROM_EMAIL: Joi.string().allow(''),
|
||||
|
||||
// Storage
|
||||
STORAGE_BUCKET: Joi.string().allow(''),
|
||||
STORAGE_REGION: Joi.string().allow(''),
|
||||
STORAGE_ENDPOINT: Joi.string().allow(''),
|
||||
STORAGE_URL_PREFIX: Joi.string().allow(''),
|
||||
STORAGE_ACCESS_KEY: Joi.string().allow(''),
|
||||
STORAGE_SECRET_KEY: Joi.string().allow(''),
|
||||
});
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
NestConfigModule.forRoot({
|
||||
load: [appConfig, authConfig, databaseConfig, googleConfig, sendgridConfig, storageConfig],
|
||||
load: [appConfig, authConfig, databaseConfig, googleConfig, sendgridConfig],
|
||||
validationSchema: validationSchema,
|
||||
}),
|
||||
],
|
||||
|
||||
@ -35,8 +35,6 @@ export class ResumeController {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
async findAllByUser(@User('id') userId: number) {
|
||||
console.log('findAllByUser', userId);
|
||||
|
||||
return this.resumeService.findAllByUser(userId);
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { DeleteObjectCommand, PutObjectCommand, S3, S3Client } from '@aws-sdk/client-s3';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@ -22,22 +21,11 @@ export const SHORT_ID_LENGTH = 8;
|
||||
|
||||
@Injectable()
|
||||
export class ResumeService {
|
||||
private s3Client: S3Client;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Resume) private resumeRepository: Repository<Resume>,
|
||||
private configService: ConfigService,
|
||||
private usersService: UsersService
|
||||
) {
|
||||
this.s3Client = new S3({
|
||||
endpoint: configService.get<string>('storage.endpoint'),
|
||||
region: configService.get<string>('storage.region'),
|
||||
credentials: {
|
||||
accessKeyId: configService.get<string>('storage.accessKey'),
|
||||
secretAccessKey: configService.get<string>('storage.secretKey'),
|
||||
},
|
||||
});
|
||||
}
|
||||
) {}
|
||||
|
||||
async create(createResumeDto: CreateResumeDto, userId: number) {
|
||||
try {
|
||||
@ -230,40 +218,29 @@ export class ResumeService {
|
||||
async uploadPhoto(id: number, userId: number, file: Express.Multer.File) {
|
||||
const resume = await this.findOne(id, userId);
|
||||
|
||||
const urlPrefix = this.configService.get<string>('storage.urlPrefix');
|
||||
const filename = new Date().getTime() + extname(file.originalname);
|
||||
const filename = id + '--' + new Date().getTime() + extname(file.originalname);
|
||||
const key = `uploads/${userId}/${id}/${filename}`;
|
||||
|
||||
await this.s3Client.send(
|
||||
new PutObjectCommand({
|
||||
Bucket: this.configService.get<string>('storage.bucket'),
|
||||
Key: key,
|
||||
Body: file.buffer,
|
||||
ACL: 'public-read',
|
||||
})
|
||||
);
|
||||
|
||||
const publicUrl = urlPrefix + key;
|
||||
|
||||
const updatedResume = set(resume, 'basics.photo.url', publicUrl);
|
||||
|
||||
const fs = require('fs');
|
||||
fs.writeFile(__dirname + '/../assets/' + key, file.buffer, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
const updatedResume = set(resume, 'basics.photo.url', '/api/assets/' + key);
|
||||
return this.resumeRepository.save<Resume>(updatedResume);
|
||||
}
|
||||
|
||||
async deletePhoto(id: number, userId: number) {
|
||||
const resume = await this.findOne(id, userId);
|
||||
|
||||
const urlPrefix = this.configService.get<string>('storage.urlPrefix');
|
||||
const publicUrl = resume.basics.photo.url;
|
||||
const key = publicUrl.replace(urlPrefix, '');
|
||||
|
||||
await this.s3Client.send(
|
||||
new DeleteObjectCommand({
|
||||
Bucket: this.configService.get<string>('storage.bucket'),
|
||||
Key: key,
|
||||
})
|
||||
);
|
||||
|
||||
const glob = require('glob');
|
||||
const fs = require('fs');
|
||||
fs.unlink(__dirname + '/../' + resume.basics.photo.url.replace('/api/', ''), (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
const updatedResume = set(resume, 'basics.photo.url', '');
|
||||
|
||||
return this.resumeRepository.save<Resume>(updatedResume);
|
||||
|
||||
Reference in New Issue
Block a user