refactor: integrate Better-Auth for authentication and remove Supabase dependencies
This commit is contained in:
@@ -61,12 +61,12 @@ function assertAvailabilityRanges(
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureComplexAccess(complexId: string, appUserId: string) {
|
||||
async function ensureComplexAccess(complexId: string, userId: string) {
|
||||
const complexUser = await db.complexUser.findUnique({
|
||||
where: {
|
||||
complexId_userId: {
|
||||
complexId,
|
||||
userId: appUserId,
|
||||
userId,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
@@ -137,14 +137,14 @@ async function enforcePlanCourtLimit(complexId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getCourtByIdForUser(courtId: string, appUserId: string) {
|
||||
async function getCourtByIdForUser(courtId: string, userId: string) {
|
||||
return db.court.findFirst({
|
||||
where: {
|
||||
id: courtId,
|
||||
complex: {
|
||||
users: {
|
||||
some: {
|
||||
userId: appUserId,
|
||||
userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -195,8 +195,8 @@ function mapCourtResponse(court: CourtWithRelations) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function listCourtsByComplex(complexId: string, appUserId: string) {
|
||||
await ensureComplexAccess(complexId, appUserId);
|
||||
export async function listCourtsByComplex(complexId: string, userId: string) {
|
||||
await ensureComplexAccess(complexId, userId);
|
||||
|
||||
const courts = await db.court.findMany({
|
||||
where: { complexId },
|
||||
@@ -218,8 +218,8 @@ export async function listCourtsByComplex(complexId: string, appUserId: string)
|
||||
return courts.map((court) => mapCourtResponse(court));
|
||||
}
|
||||
|
||||
export async function createCourt(appUserId: string, complexId: string, input: CreateCourtInput) {
|
||||
await ensureComplexAccess(complexId, appUserId);
|
||||
export async function createCourt(userId: string, complexId: string, input: CreateCourtInput) {
|
||||
await ensureComplexAccess(complexId, userId);
|
||||
await ensureActiveSport(input.sportId);
|
||||
await enforcePlanCourtLimit(complexId);
|
||||
assertAvailabilityRanges(input.availability);
|
||||
@@ -249,7 +249,7 @@ export async function createCourt(appUserId: string, complexId: string, input: C
|
||||
return court;
|
||||
});
|
||||
|
||||
const court = await getCourtByIdForUser(createdCourt.id, appUserId);
|
||||
const court = await getCourtByIdForUser(createdCourt.id, userId);
|
||||
|
||||
if (!court) {
|
||||
throw new CourtServiceError('No se pudo obtener la cancha creada.', 404);
|
||||
@@ -258,8 +258,8 @@ export async function createCourt(appUserId: string, complexId: string, input: C
|
||||
return mapCourtResponse(court);
|
||||
}
|
||||
|
||||
export async function updateCourt(appUserId: string, courtId: string, input: UpdateCourtInput) {
|
||||
const existingCourt = await getCourtByIdForUser(courtId, appUserId);
|
||||
export async function updateCourt(userId: string, courtId: string, input: UpdateCourtInput) {
|
||||
const existingCourt = await getCourtByIdForUser(courtId, userId);
|
||||
|
||||
if (!existingCourt) {
|
||||
throw new CourtServiceError('Cancha no encontrada.', 404);
|
||||
@@ -305,7 +305,7 @@ export async function updateCourt(appUserId: string, courtId: string, input: Upd
|
||||
}
|
||||
});
|
||||
|
||||
const updatedCourt = await getCourtByIdForUser(courtId, appUserId);
|
||||
const updatedCourt = await getCourtByIdForUser(courtId, userId);
|
||||
|
||||
if (!updatedCourt) {
|
||||
throw new CourtServiceError('Cancha no encontrada.', 404);
|
||||
|
||||
Reference in New Issue
Block a user