Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Minor issues #133

Merged
merged 2 commits into from
Sep 16, 2024
Merged
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
2 changes: 0 additions & 2 deletions docker/test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ services:
- POSTGRES_USER=${APPLICATION_DB_USERNAME}
- POSTGRES_PASSWORD=${APPLICATION_DB_PASSWORD}
- POSTGRES_DB=${APPLICATION_DB_DATABASE}
ports: ['${APPLICATION_DB_PORT}:5432']
env_file: ../../.env.test

test-redis:
image: redis:6
container_name: test-budget-tracker-redis
volumes: ['test_redis_data:/data']
ports: ['6379:6379']

test-runner:
build:
Expand Down
10 changes: 6 additions & 4 deletions src/controllers/categories.controller/create-category.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { z } from 'zod';
import { API_RESPONSE_STATUS, CATEGORY_TYPES, endpointsTypes } from 'shared-types';
import { API_RESPONSE_STATUS, CATEGORY_TYPES } from 'shared-types';
import { CustomResponse } from '@common/types';
import * as categoriesService from '@root/services/categories/create-category';
import { errorHandler } from '../helpers';

export const createCategory = async (req, res: CustomResponse) => {
const { id: userId } = req.user;
const { name, imageUrl, color, parentId }: endpointsTypes.CreateCategoryBody = req.validated.body;
const { name, imageUrl, color, parentId }: CreateCategoryParams = req.validated.body;

try {
const data = await categoriesService.createCategory({
Expand All @@ -29,7 +29,7 @@ export const createCategory = async (req, res: CustomResponse) => {
export const CreateCategoryPayloadSchema = z
.object({
name: z.string().min(1).max(200, 'The name must not exceed 200 characters'),
imageUrl: z.string().url().max(500, 'The URL must not exceed 500 characters').optional(),
imageUrl: z.string().url().max(500, 'The URL must not exceed 500 characters').nullish(),
type: z
.enum(Object.values(CATEGORY_TYPES) as [string, ...string[]])
.default(CATEGORY_TYPES.custom),
Expand All @@ -41,7 +41,7 @@ export const CreateCategoryPayloadSchema = z
color: z
.string()
.regex(/^#[0-9A-F]{6}$/i)
.optional(),
.nullish(),
}),
z.object({
parentId: z.undefined(),
Expand All @@ -53,3 +53,5 @@ export const CreateCategoryPayloadSchema = z
export const createCategorySchema = z.object({
body: CreateCategoryPayloadSchema,
});

type CreateCategoryParams = z.infer<typeof CreateCategoryPayloadSchema>;
Loading