refactor: make inventory images the publication source

Remove the temporary listing-level image count from the schema, validation, DTO, and draft contract. Publication now requires the persisted inventory image repository count. Add migration 0009 and update listing tests and implementation status. Verification: npm test passed 62 tests and integration passed 14 tests. No build script is configured in this repository.
This commit is contained in:
2026-09-08 17:34:59 -04:00
parent c728016dec
commit 31f11f6d56
12 changed files with 28 additions and 35 deletions
@@ -275,7 +275,6 @@ export const listings = pgTable('listings', {
.notNull()
.references(() => conditions.id),
askingPriceMinor: integer('asking_price_minor').notNull(),
imageCount: integer('image_count').notNull(),
status: listingStatus('status').default('DRAFT').notNull(),
notes: text('notes'),
...timestamps,
@@ -41,7 +41,6 @@ export function createListing({
categoryId,
conditionId,
askingPriceMinor,
imageCount,
notes,
}) {
return {
@@ -50,7 +49,6 @@ export function createListing({
categoryId: requiredText(categoryId, 'Category ID'),
conditionId: requiredText(conditionId, 'Condition ID'),
askingPriceMinor: requirePositiveMinorUnit(askingPriceMinor, 'Asking price'),
imageCount: requirePositiveInteger(imageCount, 'Image count'),
status: LISTING_STATUS.DRAFT,
...(typeof notes === 'string' && notes.trim().length > 0
? { notes: notes.trim() }
@@ -122,10 +120,3 @@ function requirePositiveMinorUnit(value, fieldName) {
return value;
}
function requirePositiveInteger(value, fieldName) {
if (!Number.isInteger(value) || value <= 0) {
throw new Error(`${fieldName} must be a positive integer.`);
}
return value;
}
@@ -8,7 +8,6 @@ import { createApplicationError } from '../../../shared/errors/application-error
export function createListingService({ listingRepository, inventoryImageRepository }) {
return {
async create(input) {
canPublishListing(input);
const listing = createListing(input);
return listingRepository.create(listing);
},
@@ -23,9 +22,7 @@ export function createListingService({ listingRepository, inventoryImageReposito
const status = transitionListingStatus(listing.status, nextStatus);
if (status === 'AVAILABLE') {
const imageCount = inventoryImageRepository
? await inventoryImageRepository.countByInventoryItemId(listing.inventoryItemId)
: listing.imageCount;
const imageCount = await inventoryImageRepository.countByInventoryItemId(listing.inventoryItemId);
canPublishListing({ ...listing, imageCount });
}