Compare commits
No commits in common. "c38c1dee24bd7070b45fd4e88cb2063d57d3dffe" and "61e4b666eff9d5c3d4c1f014587e97d765a3f753" have entirely different histories.
c38c1dee24
...
61e4b666ef
@ -20,11 +20,6 @@ const filamentStockSchema = new Schema(
|
|||||||
gross: { type: Number, required: true },
|
gross: { type: Number, required: true },
|
||||||
},
|
},
|
||||||
filamentSku: { type: mongoose.Schema.Types.ObjectId, ref: 'filamentSku', required: true },
|
filamentSku: { type: mongoose.Schema.Types.ObjectId, ref: 'filamentSku', required: true },
|
||||||
stockLocation: {
|
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
|
||||||
ref: 'stockLocation',
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|||||||
@ -12,11 +12,6 @@ const partStockSchema = new Schema(
|
|||||||
progress: { type: Number, required: false },
|
progress: { type: Number, required: false },
|
||||||
},
|
},
|
||||||
partSku: { type: mongoose.Schema.Types.ObjectId, ref: 'partSku', required: true },
|
partSku: { type: mongoose.Schema.Types.ObjectId, ref: 'partSku', required: true },
|
||||||
stockLocation: {
|
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
|
||||||
ref: 'stockLocation',
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
currentQuantity: { type: Number, required: true },
|
currentQuantity: { type: Number, required: true },
|
||||||
sourceType: { type: String, required: true },
|
sourceType: { type: String, required: true },
|
||||||
source: { type: Schema.Types.ObjectId, refPath: 'sourceType', required: true },
|
source: { type: Schema.Types.ObjectId, refPath: 'sourceType', required: true },
|
||||||
|
|||||||
@ -19,11 +19,6 @@ const productStockSchema = new Schema(
|
|||||||
},
|
},
|
||||||
postedAt: { type: Date, required: false },
|
postedAt: { type: Date, required: false },
|
||||||
productSku: { type: mongoose.Schema.Types.ObjectId, ref: 'productSku', required: true },
|
productSku: { type: mongoose.Schema.Types.ObjectId, ref: 'productSku', required: true },
|
||||||
stockLocation: {
|
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
|
||||||
ref: 'stockLocation',
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
currentQuantity: { type: Number, required: true },
|
currentQuantity: { type: Number, required: true },
|
||||||
partStocks: [partStockUsageSchema],
|
partStocks: [partStockUsageSchema],
|
||||||
},
|
},
|
||||||
|
|||||||
@ -25,7 +25,7 @@ const stockEventSchema = new Schema(
|
|||||||
ownerType: {
|
ownerType: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
enum: ['user', 'subJob', 'stockAudit', 'stockTransfer'],
|
enum: ['user', 'subJob', 'stockAudit'],
|
||||||
},
|
},
|
||||||
timestamp: { type: Date, default: Date.now },
|
timestamp: { type: Date, default: Date.now },
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
import mongoose from 'mongoose';
|
|
||||||
import { generateId } from '../../utils.js';
|
|
||||||
const { Schema } = mongoose;
|
|
||||||
|
|
||||||
const addressSchema = new Schema({
|
|
||||||
building: { required: false, type: String },
|
|
||||||
addressLine1: { required: false, type: String },
|
|
||||||
addressLine2: { required: false, type: String },
|
|
||||||
city: { required: false, type: String },
|
|
||||||
state: { required: false, type: String },
|
|
||||||
postcode: { required: false, type: String },
|
|
||||||
country: { required: false, type: String },
|
|
||||||
});
|
|
||||||
|
|
||||||
const stockLocationSchema = new Schema(
|
|
||||||
{
|
|
||||||
_reference: { type: String, default: () => generateId()() },
|
|
||||||
name: { type: String, required: true },
|
|
||||||
address: { required: false, type: addressSchema },
|
|
||||||
},
|
|
||||||
{ timestamps: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
stockLocationSchema.statics.stats = async function () {
|
|
||||||
const total = await this.countDocuments({});
|
|
||||||
return { total: { count: total } };
|
|
||||||
};
|
|
||||||
|
|
||||||
stockLocationSchema.statics.history = async function () {
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
stockLocationSchema.virtual('id').get(function () {
|
|
||||||
return this._id;
|
|
||||||
});
|
|
||||||
|
|
||||||
stockLocationSchema.set('toJSON', { virtuals: true });
|
|
||||||
|
|
||||||
export const stockLocationModel = mongoose.model('stockLocation', stockLocationSchema);
|
|
||||||
@ -1,71 +0,0 @@
|
|||||||
import mongoose from 'mongoose';
|
|
||||||
import { generateId } from '../../utils.js';
|
|
||||||
const { Schema } = mongoose;
|
|
||||||
|
|
||||||
const stockTransferLineSchema = new Schema(
|
|
||||||
{
|
|
||||||
fromStockType: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
enum: ['filamentStock', 'partStock', 'productStock'],
|
|
||||||
},
|
|
||||||
fromStock: {
|
|
||||||
type: Schema.Types.ObjectId,
|
|
||||||
refPath: 'fromStockType',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
quantity: { type: Number, required: true },
|
|
||||||
toStockLocation: {
|
|
||||||
type: Schema.Types.ObjectId,
|
|
||||||
ref: 'stockLocation',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
toStockType: {
|
|
||||||
type: String,
|
|
||||||
required: false,
|
|
||||||
enum: ['filamentStock', 'partStock', 'productStock'],
|
|
||||||
},
|
|
||||||
toStock: {
|
|
||||||
type: Schema.Types.ObjectId,
|
|
||||||
refPath: 'toStockType',
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ _id: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
const stockTransferSchema = new Schema(
|
|
||||||
{
|
|
||||||
_reference: { type: String, default: () => generateId()() },
|
|
||||||
state: {
|
|
||||||
type: { type: String, required: true, default: 'draft' },
|
|
||||||
progress: { type: Number, required: false },
|
|
||||||
},
|
|
||||||
postedAt: { type: Date, required: false },
|
|
||||||
lines: { type: [stockTransferLineSchema], default: [] },
|
|
||||||
},
|
|
||||||
{ timestamps: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
stockTransferSchema.statics.stats = async function () {
|
|
||||||
const [draft, posted] = await Promise.all([
|
|
||||||
this.countDocuments({ 'state.type': 'draft' }),
|
|
||||||
this.countDocuments({ 'state.type': 'posted' }),
|
|
||||||
]);
|
|
||||||
return {
|
|
||||||
draft: { count: draft },
|
|
||||||
posted: { count: posted },
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
stockTransferSchema.statics.history = async function () {
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
|
|
||||||
stockTransferSchema.virtual('id').get(function () {
|
|
||||||
return this._id;
|
|
||||||
});
|
|
||||||
|
|
||||||
stockTransferSchema.set('toJSON', { virtuals: true });
|
|
||||||
|
|
||||||
export const stockTransferModel = mongoose.model('stockTransfer', stockTransferSchema);
|
|
||||||
@ -56,8 +56,6 @@ const hostSchema = new mongoose.Schema(
|
|||||||
connectedAt: { required: false, type: Date },
|
connectedAt: { required: false, type: Date },
|
||||||
authCode: { type: { required: false, type: String } },
|
authCode: { type: { required: false, type: String } },
|
||||||
deviceInfo: { deviceInfoSchema },
|
deviceInfo: { deviceInfoSchema },
|
||||||
otp: { type: { required: false, type: String } },
|
|
||||||
otpExpiresAt: { required: false, type: Date },
|
|
||||||
files: [{ type: mongoose.Schema.Types.ObjectId, ref: 'file' }],
|
files: [{ type: mongoose.Schema.Types.ObjectId, ref: 'file' }],
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
|
|||||||
@ -31,10 +31,19 @@ partSchema.virtual('id').get(function () {
|
|||||||
partSchema.set('toJSON', { virtuals: true });
|
partSchema.set('toJSON', { virtuals: true });
|
||||||
|
|
||||||
partSchema.statics.recalculate = async function (part, user) {
|
partSchema.statics.recalculate = async function (part, user) {
|
||||||
const partSkuModel = mongoose.model('partSku');
|
const orderItemModel = mongoose.model('orderItem');
|
||||||
const skus = await partSkuModel.find({ part: part._id }).select('_id').lean();
|
const itemId = part._id;
|
||||||
for (const sku of skus) {
|
const draftOrderItems = await orderItemModel
|
||||||
await partSkuModel.recalculate(sku, user);
|
.find({
|
||||||
|
'state.type': 'draft',
|
||||||
|
itemType: 'part',
|
||||||
|
item: itemId,
|
||||||
|
})
|
||||||
|
.populate('order')
|
||||||
|
.lean();
|
||||||
|
|
||||||
|
for (const orderItem of draftOrderItems) {
|
||||||
|
await orderItemModel.recalculate(orderItem, user);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,6 @@ productSchema.statics.recalculate = async function (product, user) {
|
|||||||
for (const orderItem of draftOrderItems) {
|
for (const orderItem of draftOrderItems) {
|
||||||
await orderItemModel.recalculate(orderItem, user);
|
await orderItemModel.recalculate(orderItem, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create and export the model
|
// Create and export the model
|
||||||
|
|||||||
@ -17,8 +17,6 @@ import { stockEventModel } from './inventory/stockevent.schema.js';
|
|||||||
import { stockAuditModel } from './inventory/stockaudit.schema.js';
|
import { stockAuditModel } from './inventory/stockaudit.schema.js';
|
||||||
import { partStockModel } from './inventory/partstock.schema.js';
|
import { partStockModel } from './inventory/partstock.schema.js';
|
||||||
import { productStockModel } from './inventory/productstock.schema.js';
|
import { productStockModel } from './inventory/productstock.schema.js';
|
||||||
import { stockLocationModel } from './inventory/stocklocation.schema.js';
|
|
||||||
import { stockTransferModel } from './inventory/stocktransfer.schema.js';
|
|
||||||
import { auditLogModel } from './management/auditlog.schema.js';
|
import { auditLogModel } from './management/auditlog.schema.js';
|
||||||
import { userModel } from './management/user.schema.js';
|
import { userModel } from './management/user.schema.js';
|
||||||
import { appPasswordModel } from './management/apppassword.schema.js';
|
import { appPasswordModel } from './management/apppassword.schema.js';
|
||||||
@ -41,8 +39,6 @@ import { invoiceModel } from './finance/invoice.schema.js';
|
|||||||
import { clientModel } from './sales/client.schema.js';
|
import { clientModel } from './sales/client.schema.js';
|
||||||
import { salesOrderModel } from './sales/salesorder.schema.js';
|
import { salesOrderModel } from './sales/salesorder.schema.js';
|
||||||
import { marketplaceModel } from './sales/marketplace.schema.js';
|
import { marketplaceModel } from './sales/marketplace.schema.js';
|
||||||
import { listingModel } from './sales/listing.schema.js';
|
|
||||||
import { listingVarientModel } from './sales/listingvarient.schema.js';
|
|
||||||
|
|
||||||
// Map prefixes to models and id fields
|
// Map prefixes to models and id fields
|
||||||
export const models = {
|
export const models = {
|
||||||
@ -159,20 +155,6 @@ export const models = {
|
|||||||
referenceField: '_reference',
|
referenceField: '_reference',
|
||||||
label: 'Product Stock',
|
label: 'Product Stock',
|
||||||
},
|
},
|
||||||
SLN: {
|
|
||||||
model: stockLocationModel,
|
|
||||||
idField: '_id',
|
|
||||||
type: 'stockLocation',
|
|
||||||
referenceField: '_reference',
|
|
||||||
label: 'Stock Location',
|
|
||||||
},
|
|
||||||
STT: {
|
|
||||||
model: stockTransferModel,
|
|
||||||
idField: '_id',
|
|
||||||
type: 'stockTransfer',
|
|
||||||
referenceField: '_reference',
|
|
||||||
label: 'Stock Transfer',
|
|
||||||
},
|
|
||||||
ADL: {
|
ADL: {
|
||||||
model: auditLogModel,
|
model: auditLogModel,
|
||||||
idField: '_id',
|
idField: '_id',
|
||||||
@ -341,18 +323,4 @@ export const models = {
|
|||||||
label: 'Marketplace',
|
label: 'Marketplace',
|
||||||
referenceField: '_reference',
|
referenceField: '_reference',
|
||||||
},
|
},
|
||||||
LST: {
|
|
||||||
model: listingModel,
|
|
||||||
idField: '_id',
|
|
||||||
type: 'listing',
|
|
||||||
label: 'Listing',
|
|
||||||
referenceField: '_reference',
|
|
||||||
},
|
|
||||||
LVR: {
|
|
||||||
model: listingVarientModel,
|
|
||||||
idField: '_id',
|
|
||||||
type: 'listingVarient',
|
|
||||||
label: 'Listing Varient',
|
|
||||||
referenceField: '_reference',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
import mongoose from 'mongoose';
|
|
||||||
import { generateId } from '../../utils.js';
|
|
||||||
const { Schema } = mongoose;
|
|
||||||
|
|
||||||
const listingSchema = new Schema(
|
|
||||||
{
|
|
||||||
_reference: { type: String, default: () => generateId()() },
|
|
||||||
product: { type: Schema.Types.ObjectId, ref: 'product', required: false },
|
|
||||||
vendor: { type: Schema.Types.ObjectId, ref: 'vendor', required: true },
|
|
||||||
stockLocation: { type: Schema.Types.ObjectId, ref: 'stockLocation', required: true },
|
|
||||||
marketplace: { type: Schema.Types.ObjectId, ref: 'marketplace', required: true },
|
|
||||||
title: { type: String, required: false },
|
|
||||||
state: {
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
enum: ['draft', 'active', 'inactive', 'deleted', 'suspended', 'syncing'],
|
|
||||||
default: 'draft',
|
|
||||||
},
|
|
||||||
message: { type: String, required: false },
|
|
||||||
},
|
|
||||||
url: { type: String, required: false },
|
|
||||||
price: { type: Number, required: false },
|
|
||||||
currency: { type: String, required: false },
|
|
||||||
lastSyncedAt: { type: Date, required: false },
|
|
||||||
},
|
|
||||||
{ timestamps: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
listingSchema.virtual('id').get(function () {
|
|
||||||
return this._id;
|
|
||||||
});
|
|
||||||
|
|
||||||
listingSchema.set('toJSON', {
|
|
||||||
virtuals: true,
|
|
||||||
transform(doc, ret) {
|
|
||||||
if (!ret.state && ret.status) {
|
|
||||||
ret.state = { type: ret.status, message: null };
|
|
||||||
}
|
|
||||||
if (ret.status) delete ret.status;
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listingModel = mongoose.model('listing', listingSchema);
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
import mongoose from 'mongoose';
|
|
||||||
import { generateId } from '../../utils.js';
|
|
||||||
const { Schema } = mongoose;
|
|
||||||
|
|
||||||
const listingVarientSchema = new Schema(
|
|
||||||
{
|
|
||||||
_reference: { type: String, default: () => generateId()() },
|
|
||||||
listing: { type: Schema.Types.ObjectId, ref: 'listing', required: true },
|
|
||||||
product: { type: Schema.Types.ObjectId, ref: 'product', required: false },
|
|
||||||
productSku: { type: Schema.Types.ObjectId, ref: 'productSku', required: false },
|
|
||||||
state: {
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
enum: ['draft', 'active', 'inactive', 'deleted', 'suspended', 'syncing'],
|
|
||||||
default: 'draft',
|
|
||||||
},
|
|
||||||
message: { type: String, required: false },
|
|
||||||
},
|
|
||||||
price: { type: Number, required: false },
|
|
||||||
currency: { type: String, required: false },
|
|
||||||
priceTaxRate: { type: Schema.Types.ObjectId, ref: 'taxRate', required: false },
|
|
||||||
priceWithTax: { type: Number, required: false },
|
|
||||||
lastSyncedAt: { type: Date, required: false },
|
|
||||||
},
|
|
||||||
{ timestamps: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
listingVarientSchema.virtual('id').get(function () {
|
|
||||||
return this._id;
|
|
||||||
});
|
|
||||||
|
|
||||||
listingVarientSchema.set('toJSON', {
|
|
||||||
virtuals: true,
|
|
||||||
transform(doc, ret) {
|
|
||||||
if (!ret.state && ret.status) {
|
|
||||||
ret.state = { type: ret.status, message: null };
|
|
||||||
}
|
|
||||||
if (ret.status) delete ret.status;
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const listingVarientModel = mongoose.model('listingVarient', listingVarientSchema);
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import { editObject } from '../../database.js';
|
|
||||||
import { generateId } from '../../utils.js';
|
import { generateId } from '../../utils.js';
|
||||||
|
|
||||||
const marketplaceSchema = new mongoose.Schema(
|
const marketplaceSchema = new mongoose.Schema(
|
||||||
@ -12,16 +11,6 @@ const marketplaceSchema = new mongoose.Schema(
|
|||||||
enum: ['ebay', 'etsy', 'tiktokShop'],
|
enum: ['ebay', 'etsy', 'tiktokShop'],
|
||||||
},
|
},
|
||||||
active: { required: true, type: Boolean, default: true },
|
active: { required: true, type: Boolean, default: true },
|
||||||
connected: { type: Boolean, required: true, default: false },
|
|
||||||
connectedAt: { type: Date, required: false },
|
|
||||||
state: {
|
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
enum: ['active', 'inactive', 'suspended', 'ready', 'offline', 'syncing'],
|
|
||||||
default: 'offline',
|
|
||||||
},
|
|
||||||
message: { type: String, required: false },
|
|
||||||
},
|
|
||||||
// Provider-specific API configuration (flexible for eBay, Etsy, TikTok Shop)
|
// Provider-specific API configuration (flexible for eBay, Etsy, TikTok Shop)
|
||||||
config: { type: mongoose.Schema.Types.Mixed, default: {} },
|
config: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||||
},
|
},
|
||||||
@ -32,26 +21,6 @@ marketplaceSchema.virtual('id').get(function () {
|
|||||||
return this._id;
|
return this._id;
|
||||||
});
|
});
|
||||||
|
|
||||||
marketplaceSchema.statics.recalculate = async function (marketplace, user) {
|
|
||||||
let stateType;
|
|
||||||
if (marketplace.active === false) {
|
|
||||||
stateType = 'inactive';
|
|
||||||
} else if (marketplace.connected === false) {
|
|
||||||
stateType = 'disconnected';
|
|
||||||
} else {
|
|
||||||
stateType = 'ready';
|
|
||||||
}
|
|
||||||
console.log('recalculating marketplace state', stateType);
|
|
||||||
marketplace.state = { type: stateType };
|
|
||||||
await editObject({
|
|
||||||
model: this,
|
|
||||||
id: marketplace._id,
|
|
||||||
updateData: { state: { type: stateType } },
|
|
||||||
user,
|
|
||||||
recalculate: false,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
marketplaceSchema.set('toJSON', { virtuals: true });
|
marketplaceSchema.set('toJSON', { virtuals: true });
|
||||||
|
|
||||||
export const marketplaceModel = mongoose.model('marketplace', marketplaceSchema);
|
export const marketplaceModel = mongoose.model('marketplace', marketplaceSchema);
|
||||||
|
|||||||
@ -23,12 +23,9 @@ export async function generateHostOTP(id) {
|
|||||||
const otpHost = await editObject({
|
const otpHost = await editObject({
|
||||||
model: hostModel,
|
model: hostModel,
|
||||||
id: id,
|
id: id,
|
||||||
updateData: { otp: otp, otpExpiresAt: expiresAt },
|
updateData: { otp: otp, otpExpiresAt: expiresAt }
|
||||||
auditLog: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('otpHost', otpHost);
|
|
||||||
|
|
||||||
return otpHost;
|
return otpHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user