-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
84 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
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,3 +1,3 @@ | ||
|
||
import { handlers } from "@/auth/auth" | ||
import { handlers } from "@/src/auth/auth" | ||
export const { GET, POST } = handlers |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use server' | ||
import { auth } from '@/src/auth/auth'; | ||
import { getUserID, getUserName } from '@/src/utils/userInfo'; | ||
import { sql } from '@vercel/postgres'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function createJob(formData: FormData) { | ||
console.log('createJob', formData) | ||
|
||
const rawFormData = Object.fromEntries(formData.entries()); | ||
|
||
const jobTitle = rawFormData.position as string; | ||
const money = rawFormData.salary as string; | ||
const jobDescription = rawFormData.description as string; | ||
|
||
try { | ||
const session = await auth(); | ||
if (!session || !session.user || !session.user.accessToken) { | ||
throw new Error("Usuario no autenticado"); | ||
} | ||
|
||
console.log(session); | ||
|
||
if (!money) { | ||
return ("Cantidad de dinero inválida"); | ||
} | ||
if (!jobTitle) { | ||
return ("El título del trabajo es obligatorio"); | ||
} | ||
if (!jobDescription) { | ||
return ("La descripción del trabajo es obligatoria"); | ||
} | ||
|
||
const username = await getUserName(); | ||
const userid = await getUserID(); | ||
|
||
await sql` | ||
INSERT INTO oferta (identify, imagen, usuario, pago, descripcion, titulo) | ||
VALUES (${userid}, ${session.user.image}, ${username}, ${money}, ${jobDescription}, ${jobTitle}) | ||
`; | ||
|
||
return "Succesful"; | ||
} catch (error) { | ||
return "Error"; | ||
} | ||
} | ||
|
||
|
||
|