Add admin stale/outlier indicators and audited manual valuation overrides, with robust submission behavior and authenticated E2E coverage.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { RouterLink } from 'vue-router';
|
||||
|
||||
import { useAuth } from '@/composables/useAuth.js';
|
||||
@@ -9,7 +9,7 @@ import { createAdminListing, listAdminListings, markListingPending, publishAdmin
|
||||
import { createAdminSale, listAdminSales, voidAdminSale } from '@/services/admin-sale-service.js';
|
||||
import { createAdminAcquisition, listAdminAcquisitions } from '@/services/admin-acquisition-service.js';
|
||||
import { getAdminDashboard } from '@/services/admin-dashboard-service.js';
|
||||
import { addAdminPricingObservation, calculateAdminValuation } from '@/services/admin-pricing-service.js';
|
||||
import { addAdminPricingObservation, calculateAdminValuation, overrideAdminValuation } from '@/services/admin-pricing-service.js';
|
||||
|
||||
const { principal } = useAuth();
|
||||
const products = ref([]);
|
||||
@@ -19,6 +19,7 @@ const sales = ref([]);
|
||||
const acquisitions = ref([]);
|
||||
const dashboard = ref(null);
|
||||
const valuations = ref({});
|
||||
const hasValuations = computed(() => Object.keys(valuations.value).length > 0);
|
||||
const categories = ref([]);
|
||||
const conditions = ref([]);
|
||||
const isLoading = ref(true);
|
||||
@@ -44,6 +45,8 @@ const pricingInventoryId = ref('');
|
||||
const pricingProvider = ref('manual');
|
||||
const pricingSource = ref('');
|
||||
const pricingPrice = ref('');
|
||||
const overridePrice = ref('');
|
||||
const overrideReason = ref('');
|
||||
const voidReasons = ref({});
|
||||
|
||||
function csrfToken() {
|
||||
@@ -151,6 +154,20 @@ async function calculatePricing() {
|
||||
finally { isSaving.value = false; }
|
||||
}
|
||||
|
||||
async function overridePricing() {
|
||||
isSaving.value = true;
|
||||
try {
|
||||
const valuation = await overrideAdminValuation(pricingInventoryId.value, {
|
||||
valueMinor: Number(overridePrice.value),
|
||||
reason: overrideReason.value,
|
||||
}, csrfToken());
|
||||
valuations.value = { ...valuations.value, [pricingInventoryId.value]: { ...valuations.value[pricingInventoryId.value], valueMinor: valuation.valueMinor, confidence: 'OVERRIDE', stale: false } };
|
||||
overridePrice.value = '';
|
||||
overrideReason.value = '';
|
||||
} catch (requestError) { error.value = requestError; }
|
||||
finally { isSaving.value = false; }
|
||||
}
|
||||
|
||||
async function voidSale(saleId) {
|
||||
isSaving.value = true;
|
||||
try {
|
||||
@@ -274,6 +291,11 @@ onMounted(load);
|
||||
<label class="fixture-label" for="pricing-price">Observed price (cents)</label>
|
||||
<input id="pricing-price" v-model="pricingPrice" class="fixture-input" type="number" min="1" required />
|
||||
<button class="button button--primary" type="submit" :disabled="isSaving">Add observation and calculate</button>
|
||||
<label class="fixture-label" for="override-price">Manual value (cents)</label>
|
||||
<input id="override-price" v-model="overridePrice" class="fixture-input" type="number" min="0" />
|
||||
<label class="fixture-label" for="override-reason">Override reason</label>
|
||||
<input id="override-reason" v-model="overrideReason" class="fixture-input" minlength="3" />
|
||||
<button class="button button--secondary" type="button" :disabled="isSaving" @click="overridePricing">Save manual value</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -286,8 +308,11 @@ onMounted(load);
|
||||
<h2 id="inventory-title">Physical inventory</h2>
|
||||
<p v-if="!inventory.length && !isLoading" class="state state--empty">No physical copies yet.</p>
|
||||
<ul v-else><li v-for="item in inventory" :key="item.id" :data-product-id="item.productId"><span>{{ item.id }}</span> · {{ item.status }} <RouterLink :to="{ name: 'admin-image-manager', params: { id: item.id } }">Manage images</RouterLink></li></ul>
|
||||
<ul v-if="Object.keys(valuations).length" aria-label="Market valuations">
|
||||
<li v-for="(valuation, inventoryItemId) in valuations" :key="inventoryItemId">{{ inventoryItemId }} · Market value ${{ (valuation.valueMinor / 100).toFixed(2) }} · {{ valuation.confidence }} confidence · {{ valuation.sourceCount }} source{{ valuation.sourceCount === 1 ? '' : 's' }}</li>
|
||||
<ul v-if="hasValuations" aria-label="Market valuations">
|
||||
<li v-for="(valuation, inventoryItemId) in valuations" :key="inventoryItemId">
|
||||
{{ inventoryItemId }} · Market value ${{ (valuation.valueMinor / 100).toFixed(2) }} · {{ valuation.confidence }} confidence · {{ valuation.sourceCount }} source{{ valuation.sourceCount === 1 ? '' : 's' }}<span v-if="valuation.stale"> · STALE</span>
|
||||
<span v-if="valuation.observations?.some(({ isOutlier }) => isOutlier)"> · OUTLIER FLAGGED</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="admin-list" aria-labelledby="listings-title">
|
||||
|
||||
@@ -25,3 +25,11 @@ export function calculateAdminValuation(inventoryItemId, csrfToken) {
|
||||
headers: { 'x-csrf-token': csrfToken },
|
||||
});
|
||||
}
|
||||
|
||||
export function overrideAdminValuation(inventoryItemId, input, csrfToken) {
|
||||
return request(`/admin/inventory/${encodeURIComponent(inventoryItemId)}/valuation/override`, {
|
||||
method: 'POST',
|
||||
headers: { 'x-csrf-token': csrfToken },
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user