Skip to content

Commit

Permalink
feat: created_at column in job offer model
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykomiotek committed Mar 21, 2024
1 parent 43a8c30 commit 2a362cd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apps/jobboard/src/app/(public)/job-offers/create/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import db from '@jobboard/prisma-client';
import { redirect } from 'next/navigation';
import { CreateOfferDto, offerSchema } from './types';
import { CreateOfferDto, createOfferSchema } from './types';
import { ZodError } from 'zod';

// export const createJobOfferAction = async (data: FormData) => {
Expand All @@ -26,7 +26,7 @@ export const createJobOfferAction = async (data: CreateOfferDto) => {
// });

try {
const offer = offerSchema.parse(data);
const offer = createOfferSchema.parse(data);

await db.jobOffer.create({ data: offer });

Expand Down
4 changes: 2 additions & 2 deletions apps/jobboard/src/app/(public)/job-offers/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Alert, Button, Header, Input } from '@jobboard/common-ui';

import { createJobOfferAction } from './actions';
import { CreateOfferDto, offerSchema } from './types';
import { CreateOfferDto, createOfferSchema } from './types';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { use, useState, useTransition } from 'react';
Expand All @@ -15,7 +15,7 @@ export default function CreateOfferPage() {
handleSubmit,
formState: { errors },
} = useForm<CreateOfferDto>({
resolver: zodResolver(offerSchema),
resolver: zodResolver(createOfferSchema),
});
const router = useRouter();
const [isPending, setTransition] = useTransition();
Expand Down
4 changes: 2 additions & 2 deletions apps/jobboard/src/app/(public)/job-offers/create/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod';

export const offerSchema = z.object({
export const createOfferSchema = z.object({
title: z
.string()
.min(3, 'Must be at least 3 characters')
Expand All @@ -27,4 +27,4 @@ export const offerSchema = z.object({
.max(50, 'Must be at least 50 characters'),
});

export type CreateOfferDto = z.infer<typeof offerSchema>;
export type CreateOfferDto = z.infer<typeof createOfferSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "JobOffer" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
7 changes: 4 additions & 3 deletions libs/prisma-schema/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ datasource db {
}

model JobOffer {
id Int @id @default(autoincrement())
public_id String @unique @default(uuid())
id Int @id @default(autoincrement())
public_id String @unique @default(uuid())
title String
description String
position String
salary Float
company String
city String? @db.VarChar(100)
city String? @db.VarChar(100)
created_at DateTime @default(now())
}

0 comments on commit 2a362cd

Please sign in to comment.