-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from framgia/HRIS-374
HRIS-374 [BE] Navbar:Time In
- Loading branch information
Showing
14 changed files
with
4,890 additions
and
1,727 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { diskStorage } from 'multer'; | ||
import { extname } from 'path'; | ||
|
||
export const multerOptions = { | ||
storage: diskStorage({ | ||
destination: './uploads', | ||
filename: (_req, file, cb) => { | ||
const randomName = Array(32) | ||
.fill(null) | ||
.map(() => Math.round(Math.random() * 16).toString(16)) | ||
.join(''); | ||
return cb(null, `${randomName}${extname(file.originalname)}`); | ||
}, | ||
}), | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
app.enableCors(); | ||
|
||
await app.listen(3001); | ||
} | ||
bootstrap(); |
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,44 @@ | ||
// src/storage/storage.service.ts | ||
|
||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { S3 } from 'aws-sdk'; | ||
|
||
@Injectable() | ||
export class StorageService { | ||
private s3: S3; | ||
|
||
constructor(private configService: ConfigService) { | ||
// Initialize AWS S3 | ||
this.s3 = new S3({ | ||
accessKeyId: this.configService.get('AWS_ACCESS_KEY_ID'), | ||
secretAccessKey: this.configService.get('AWS_SECRET_ACCESS_KEY'), | ||
region: this.configService.get('AWS_REGION'), | ||
}); | ||
} | ||
|
||
async uploadFile(file: Express.Multer.File): Promise<string> { | ||
if (this.configService.get('AWS_ACCESS_KEY_ID')) { | ||
return this.uploadToS3(file); | ||
} else { | ||
throw new Error('No storage configuration found'); | ||
} | ||
} | ||
|
||
private async uploadToS3(file: Express.Multer.File): Promise<string> { | ||
const uploadParams = { | ||
Bucket: this.configService.get('S3_BUCKET_NAME'), | ||
Key: `${Date.now()}-${file.originalname}`, | ||
Body: file.buffer, | ||
ACL: 'public-read', | ||
}; | ||
|
||
try { | ||
const result = await this.s3.upload(uploadParams).promise(); | ||
return result.Location; | ||
} catch (error) { | ||
console.error('Error uploading file to S3:', error); | ||
throw new Error('Failed to upload file to S3'); | ||
} | ||
} | ||
} |
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,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TimeInService } from './time-in.service'; | ||
import { TimeInResolver } from './time-in.resolver'; | ||
import { PrismaService } from '@/prisma/prisma.service'; | ||
import { TimeInServiceInputValidation } from '@/utilities/validation/timeInServiceInputValidation'; | ||
import { FileUploadService } from '@/file-upload/file-upload.service'; | ||
|
||
@Module({ | ||
providers: [ | ||
TimeInResolver, | ||
TimeInService, | ||
PrismaService, | ||
TimeInServiceInputValidation, | ||
FileUploadService, | ||
], | ||
}) | ||
export class TimeInModule {} |
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,28 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { TimeInResolver } from './time-in.resolver'; | ||
import { TimeInService } from './time-in.service'; | ||
import { PrismaService } from '@/prisma/prisma.service'; | ||
import { TimeInServiceInputValidation } from '@/utilities/validation/timeInServiceInputValidation'; | ||
import { FileUploadService } from '@/file-upload/file-upload.service'; | ||
|
||
describe('TimeInResolver', () => { | ||
let resolver: TimeInResolver; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
TimeInResolver, | ||
TimeInService, | ||
PrismaService, | ||
TimeInServiceInputValidation, | ||
FileUploadService, | ||
], | ||
}).compile(); | ||
|
||
resolver = module.get<TimeInResolver>(TimeInResolver); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(resolver).toBeDefined(); | ||
}); | ||
}); |
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,27 @@ | ||
import { Resolver, Mutation, Args } from '@nestjs/graphql'; | ||
import { TimeInService } from './time-in.service'; | ||
import { TimeInRequestInput } from '@/graphql/graphql'; | ||
import { GraphQLError } from 'graphql'; | ||
import { Logger } from '@nestjs/common'; | ||
|
||
@Resolver() | ||
export class TimeInResolver { | ||
private readonly logger = new Logger(); | ||
constructor(private readonly timeInService: TimeInService) {} | ||
|
||
@Mutation(() => String) | ||
async updateTimeIn( | ||
@Args('timeIn') timeIn: TimeInRequestInput, | ||
): Promise<string> { | ||
try { | ||
this.logger.log('timeIn', timeIn); | ||
const result = await this.timeInService.update(timeIn); | ||
return result; | ||
} catch (error) { | ||
if (error instanceof GraphQLError) { | ||
throw error; | ||
} | ||
throw new Error(error.message || 'Something went wrong...'); | ||
} | ||
} | ||
} |
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,26 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { TimeInService } from './time-in.service'; | ||
import { PrismaService } from '@/prisma/prisma.service'; | ||
import { TimeInServiceInputValidation } from '@/utilities/validation/timeInServiceInputValidation'; | ||
import { FileUploadService } from '@/file-upload/file-upload.service'; | ||
|
||
describe('TimeInService', () => { | ||
let service: TimeInService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
TimeInService, | ||
PrismaService, | ||
TimeInServiceInputValidation, | ||
FileUploadService, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<TimeInService>(TimeInService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.