import { db } from "$lib/server/connections/drizzle/drizzleClient";
import { person } from "$lib/server/connections/drizzle/schema";
import type { Person } from "$lib/types/database/databaseTypes";
export async function createOrUpdatePerson(inputPerson: Person) {
try {
let response;
// Check if it is update (if the id is already filled)
{
const currentTimestamp = new Date().getTime();
inputPerson.updatedAt= new Date(currentTimestamp).toString();
response = await db.update(person).set(inputPerson).returning({personId: person.id})
}
// If not, it is a creation
else{
const currentTimestamp = new Date().getTime();
inputPerson.createdAt= new Date(currentTimestamp).toString();
response = await db.insert(person).values(inputPerson).returning({personId: person.id})
}
return {success: true}
}
catch(error){
return {success: false, errorMessage: error}
}
}
import { db } from "$lib/server/connections/drizzle/drizzleClient";
import { person } from "$lib/server/connections/drizzle/schema";
import type { Person } from "$lib/types/database/databaseTypes";
export async function createOrUpdatePerson(inputPerson: Person) {
try {
let response;
// Check if it is update (if the id is already filled)
{
const currentTimestamp = new Date().getTime();
inputPerson.updatedAt= new Date(currentTimestamp).toString();
response = await db.update(person).set(inputPerson).returning({personId: person.id})
}
// If not, it is a creation
else{
const currentTimestamp = new Date().getTime();
inputPerson.createdAt= new Date(currentTimestamp).toString();
response = await db.insert(person).values(inputPerson).returning({personId: person.id})
}
return {success: true}
}
catch(error){
return {success: false, errorMessage: error}
}
}