Skip to content

Commit

Permalink
fix(api): fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrl23 committed Sep 1, 2024
1 parent 82ce54e commit e72a0c7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 84 deletions.
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ model File {
Project Project? @relation(fields: [projectId], references: [id])
projectId String?
Testament Testament[]
Testimonial Testimonial[]
}

model Project {
Expand All @@ -47,7 +47,7 @@ model AuthApiKey {
revoked Boolean @default(false)
}

model Testament {
model Testimonial {
id String @id @default(uuid()) @map("_id")
createdAt DateTime @default(now())
Expand Down
6 changes: 3 additions & 3 deletions src/modules/auth/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const permissions = [
'projects.write',
'projects.delete',
'emails.write',
'testaments.read',
'testaments.write',
'testaments.delete',
'testimonials.read',
'testimonials.write',
'testimonials.delete',
] as const;

export type Permission = (typeof permissions)[number];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { REDIS_URL } from '../../lib/constant/env';
import { authApiPermissionHandler } from '../auth/authPreHandler';
import { CacheService } from '../cache/cacheService';
import {
testamentCreateSchema,
testamentDeleteSchema,
testamentListPayloadSchema,
testamentSchema,
} from './testamentsSchema';
import { TestamentsService } from './testamentsService';
testimonialCreateSchema,
testimonialDeleteSchema,
testimonialListPayloadSchema,
testimonialSchema,
} from './testimonialsSchema';
import { TestimonialsService } from './testimonialsService';
import { File } from 'fastify-multer/lib/interfaces';

declare module 'fastify' {
Expand All @@ -26,12 +26,12 @@ declare module 'fastify' {
}

export default asRoute(async function (app) {
const testamentsService = new TestamentsService(
const testimonialsService = new TestimonialsService(
new CacheService(
await caching(
redisStore({
url: REDIS_URL,
prefix: 'Portfolio:TestamentsService',
prefix: 'Portfolio:TestimonialsService',
ttl: ms('7d'),
}),
),
Expand Down Expand Up @@ -61,33 +61,33 @@ export default asRoute(async function (app) {
},
},
schema: {
description: 'create testament',
tags: ['testaments'],
description: 'create testimonial',
tags: ['testimonials'],
consumes: ['multipart/form-data'],
body: testamentCreateSchema,
body: testimonialCreateSchema,
response: {
200: {
description: 'testament',
description: 'testimonial',
type: 'object',
required: ['data'],
properties: {
data: testamentSchema,
data: testimonialSchema,
},
},
},
},
preValidation: [upload.single('image')],
async handler(
request: FastifyRequest<{
Body: FromSchema<typeof testamentCreateSchema>;
Body: FromSchema<typeof testimonialCreateSchema>;
}>,
) {
const testament = await testamentsService.createTestament({
const testimonial = await testimonialsService.createTestimonial({
...request.body,
image: request.file,
});
return {
data: testament,
data: testimonial,
};
},
})
Expand All @@ -102,12 +102,12 @@ export default asRoute(async function (app) {
},
},
schema: {
description: 'generate testament key',
description: 'generate testimonial key',
security: [{ bearerAuth: [] }],
tags: ['testaments'],
tags: ['testimonials'],
response: {
200: {
description: 'testament',
description: 'testimonial',
type: 'object',
required: ['data'],
properties: {
Expand All @@ -120,9 +120,9 @@ export default asRoute(async function (app) {
},
},
},
preHandler: [authApiPermissionHandler('testaments.write')],
preHandler: [authApiPermissionHandler('testimonials.write')],
async handler() {
const key = await testamentsService.generateKey();
const key = await testimonialsService.generateKey();
return {
data: key,
};
Expand All @@ -139,35 +139,35 @@ export default asRoute(async function (app) {
},
},
schema: {
description: 'get testaments',
description: 'get testimonials',
security: [{ bearerAuth: [] }],
tags: ['testaments'],
querystring: testamentListPayloadSchema,
tags: ['testimonials'],
querystring: testimonialListPayloadSchema,
response: {
200: {
description: 'testaments',
description: 'testimonials',
type: 'object',
required: ['data'],
properties: {
data: {
type: 'array',
items: testamentSchema,
items: testimonialSchema,
},
},
},
},
},
preHandler: [authApiPermissionHandler('testaments.read')],
preHandler: [authApiPermissionHandler('testimonials.read')],
async handler(
request: FastifyRequest<{
Querystring: FromSchema<typeof testamentListPayloadSchema>;
Querystring: FromSchema<typeof testimonialListPayloadSchema>;
}>,
) {
const testaments = await testamentsService.getTestamentsByPayload(
const testimonials = await testimonialsService.getTestimonialsByPayload(
request.query,
);
return {
data: testaments,
data: testimonials,
};
},
})
Expand All @@ -182,32 +182,32 @@ export default asRoute(async function (app) {
},
},
schema: {
description: 'delete testament',
description: 'delete testimonial',
security: [{ bearerAuth: [] }],
tags: ['testaments'],
querystring: testamentDeleteSchema,
tags: ['testimonials'],
params: testimonialDeleteSchema,
response: {
200: {
description: 'testament',
description: 'testimonial',
type: 'object',
required: ['data'],
properties: {
data: testamentSchema,
data: testimonialSchema,
},
},
},
},
preHandler: [authApiPermissionHandler('testaments.delete')],
preHandler: [authApiPermissionHandler('testimonials.delete')],
async handler(
request: FastifyRequest<{
Params: FromSchema<typeof testamentDeleteSchema>;
Params: FromSchema<typeof testimonialDeleteSchema>;
}>,
) {
const testament = await testamentsService.deleteTestamentById(
const testimonial = await testimonialsService.deleteTestimonialById(
request.params.id,
);
return {
data: testament,
data: testimonial,
};
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { asJsonSchema } from '../../lib/common';
import { fileSchema } from '../files/filesSchema';

export const testamentSchema = asJsonSchema({
export const testimonialSchema = asJsonSchema({
type: 'object',
additionalProperties: false,
required: ['id', 'createdAt', 'author', 'bio', 'content', 'image'],
Expand Down Expand Up @@ -31,7 +31,7 @@ export const testamentSchema = asJsonSchema({
},
});

export const testamentCreateSchema = asJsonSchema({
export const testimonialCreateSchema = asJsonSchema({
type: 'object',
additionalProperties: false,
required: ['author', 'content', 'key'],
Expand Down Expand Up @@ -60,7 +60,7 @@ export const testamentCreateSchema = asJsonSchema({
},
});

export const testamentListPayloadSchema = asJsonSchema({
export const testimonialListPayloadSchema = asJsonSchema({
type: 'object',
additionalProperties: false,
properties: {
Expand Down Expand Up @@ -114,7 +114,7 @@ export const testamentListPayloadSchema = asJsonSchema({
},
});

export const testamentDeleteSchema = asJsonSchema({
export const testimonialDeleteSchema = asJsonSchema({
type: 'object',
additionalProperties: false,
required: ['id'],
Expand Down
Loading

0 comments on commit e72a0c7

Please sign in to comment.