Compare commits
No commits in common. "b2afa1fae0beb009f590e53f57f92b10d30ae778" and "69d5d33530f951453b3334f9503fa9d338802820" have entirely different histories.
b2afa1fae0
...
69d5d33530
2 changed files with 5 additions and 18 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { ListingStatus, Role, UserStatus } from '@prisma/client';
|
import { ListingStatus, UserRole, UserStatus } from '@prisma/client';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { prisma } from '../../../../lib/prisma';
|
import { prisma } from '../../../../lib/prisma';
|
||||||
import { requireAuth } from '../../../../lib/jwt';
|
import { requireAuth } from '../../../../lib/jwt';
|
||||||
|
|
@ -117,7 +117,7 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = existing.status;
|
let status = existing.status;
|
||||||
const autoApprove = !saveDraft && (process.env.AUTO_APPROVE_LISTINGS === 'true' || auth.role === Role.ADMIN);
|
const autoApprove = !saveDraft && (process.env.AUTO_APPROVE_LISTINGS === 'true' || auth.role === UserRole.ADMIN);
|
||||||
if (saveDraft) {
|
if (saveDraft) {
|
||||||
status = ListingStatus.DRAFT;
|
status = ListingStatus.DRAFT;
|
||||||
} else if (existing.status === ListingStatus.PUBLISHED) {
|
} else if (existing.status === ListingStatus.PUBLISHED) {
|
||||||
|
|
@ -186,7 +186,7 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
|
||||||
const updateData: any = {
|
const updateData: any = {
|
||||||
status,
|
status,
|
||||||
approvedAt: status === ListingStatus.PUBLISHED ? existing.approvedAt ?? new Date() : null,
|
approvedAt: status === ListingStatus.PUBLISHED ? existing.approvedAt ?? new Date() : null,
|
||||||
approvedById: status === ListingStatus.PUBLISHED && auth.role === Role.ADMIN ? auth.userId : existing.approvedById,
|
approvedById: status === ListingStatus.PUBLISHED && auth.role === UserRole.ADMIN ? auth.userId : existing.approvedById,
|
||||||
country: country || null,
|
country: country || null,
|
||||||
region: region || null,
|
region: region || null,
|
||||||
city: city || null,
|
city: city || null,
|
||||||
|
|
|
||||||
|
|
@ -88,12 +88,8 @@ export default function EditListingPage({ params }: { params: { id: string } })
|
||||||
}
|
}
|
||||||
const listing = data.listing;
|
const listing = data.listing;
|
||||||
setInitialStatus(listing.status as ListingStatus);
|
setInitialStatus(listing.status as ListingStatus);
|
||||||
const translationMap: Record<Locale, LocaleFields> = {
|
const translationMap = { ...translations };
|
||||||
en: { title: '', description: '', teaser: '' },
|
const slugMap = { ...suggestedSlugs };
|
||||||
fi: { title: '', description: '', teaser: '' },
|
|
||||||
sv: { title: '', description: '', teaser: '' },
|
|
||||||
};
|
|
||||||
const slugMap: Record<Locale, string> = { en: '', fi: '', sv: '' };
|
|
||||||
SUPPORTED_LOCALES.forEach((loc) => {
|
SUPPORTED_LOCALES.forEach((loc) => {
|
||||||
const found = listing.translations.find((t: any) => t.locale === loc);
|
const found = listing.translations.find((t: any) => t.locale === loc);
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
@ -142,15 +138,6 @@ export default function EditListingPage({ params }: { params: { id: string } })
|
||||||
if (listing.images?.length) {
|
if (listing.images?.length) {
|
||||||
const coverIdx = listing.images.find((img: any) => img.isCover)?.order ?? 1;
|
const coverIdx = listing.images.find((img: any) => img.isCover)?.order ?? 1;
|
||||||
setCoverImageIndex(coverIdx);
|
setCoverImageIndex(coverIdx);
|
||||||
setSelectedImages(
|
|
||||||
listing.images.map((img: any) => ({
|
|
||||||
name: img.altText || img.url || `image-${img.id}`,
|
|
||||||
size: img.size || 0,
|
|
||||||
mimeType: img.mimeType || 'image/jpeg',
|
|
||||||
dataUrl: img.url || `/api/images/${img.id}`,
|
|
||||||
isExisting: true,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError(err.message || 'Failed to load listing');
|
setError(err.message || 'Failed to load listing');
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue