@stacksjs/commerce 0.75.569 → 0.75.571
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUIDv7}from"bun";import{db}from"@stacksjs/database/runtime";import{asModelRow}from"../../utils/model-row";export async function store(data){try{return await db.transaction(async(trx)=>{const unitData={...data,uuid:randomUUIDv7()};const result=await trx.insertInto("product_units").values(unitData).returningAll().executeTakeFirst();if(!result)throw new Error("Failed to create product unit");if(unitData.is_default&&unitData.type){await trx.updateTable("product_units").set({is_default:false}).where("type","=",unitData.type).where("id","!=",result.id).execute()}return asModelRow(result)})}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create product unit: ${error.message}`)}throw error}}export async function bulkStore(data){if(!data.length)return 0;let createdCount=0;try{for(const unit of data){const unitData={...unit,uuid:randomUUIDv7()};const result=await db.insertInto("product_units").values(unitData).returningAll().executeTakeFirst();if(unitData.is_default&&unitData.type&&result){await db.updateTable("product_units").set({is_default:false}).where("type","=",unitData.type).where("id","!=",result.id).execute()}createdCount++}return createdCount}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create product units in bulk: ${error.message}`)}throw error}}export function formatUnitOptions(type){try{let query=db.selectFrom("product_units").select(["id","name","abbreviation","is_default"]);if(type)query=query.where("type","=",type);query=query.orderBy("name");
|
|
1
|
+
import{randomUUIDv7}from"bun";import{db}from"@stacksjs/database/runtime";import{asModelRow}from"../../utils/model-row";export async function store(data){try{return await db.transaction(async(trx)=>{const unitData={...data,uuid:randomUUIDv7()};const result=await trx.insertInto("product_units").values(unitData).returningAll().executeTakeFirst();if(!result)throw new Error("Failed to create product unit");if(unitData.is_default&&unitData.type){await trx.updateTable("product_units").set({is_default:false}).where("type","=",unitData.type).where("id","!=",result.id).execute()}return asModelRow(result)})}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create product unit: ${error.message}`)}throw error}}export async function bulkStore(data){if(!data.length)return 0;let createdCount=0;try{for(const unit of data){const unitData={...unit,uuid:randomUUIDv7()};const result=await db.insertInto("product_units").values(unitData).returningAll().executeTakeFirst();if(unitData.is_default&&unitData.type&&result){await db.updateTable("product_units").set({is_default:false}).where("type","=",unitData.type).where("id","!=",result.id).execute()}createdCount++}return createdCount}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create product units in bulk: ${error.message}`)}throw error}}export async function formatUnitOptions(type){try{let query=db.selectFrom("product_units").select(["id","name","abbreviation","is_default"]);if(type)query=query.where("type","=",type);query=query.orderBy("name");const results=await query.execute();return results.map((result)=>({id:String(result.id),name:result.name,abbreviation:result.abbreviation,is_default:result.is_default}))}catch(error){if(error instanceof Error){throw new TypeError(`Failed to format unit options: ${error.message}`)}throw error}}export async function getDefaultUnit(type){try{const defaultUnit=await db.selectFrom("product_units").selectAll().where("type","=",type).where("is_default","=",true).executeTakeFirst();return asModelRow(defaultUnit,true)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to get default unit: ${error.message}`)}throw error}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUIDv7}from"bun";import{db}from"@stacksjs/database/runtime";import{asModelRow,asModelRows}from"../../utils/model-row";import{mutationCount}from"../../utils/mutation-count";import{shippingMethodWriteData}from"../write-data";export async function store(data){try{const uuid=randomUUIDv7();const shippingData={...shippingMethodWriteData(data),uuid};await db.insertInto("shipping_methods").values(shippingData).executeTakeFirst();const model=await db.selectFrom("shipping_methods").where("uuid","=",uuid).selectAll().executeTakeFirst();if(!model)throw new Error("Failed to resolve created shipping method");return asModelRow(model)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create shipping method: ${error.message}`)}throw error}}export async function bulkStore(data){if(!data.length)return 0;try{const shippingDataArray=data.map((item)=>({...shippingMethodWriteData(item),uuid:randomUUIDv7()}));const result=await db.insertInto("shipping_methods").values(shippingDataArray).executeTakeFirst();return mutationCount(result)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create shipping methods in bulk: ${error.message}`)}throw error}}export function formatShippingOptions(){try{return db.selectFrom("shipping_methods").select(["id","name","status","base_rate"]).orderBy("name").execute()}catch(error){if(error instanceof Error){throw new TypeError(`Failed to format shipping options: ${error.message}`)}throw error}}export async function getActiveShippingMethods(){try{const rows=await db.selectFrom("shipping_methods").selectAll().where("status","=","active").orderBy("name").execute();return asModelRows(rows)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to get active shipping methods: ${error.message}`)}throw error}}
|
|
1
|
+
import{randomUUIDv7}from"bun";import{db}from"@stacksjs/database/runtime";import{asModelRow,asModelRows}from"../../utils/model-row";import{mutationCount}from"../../utils/mutation-count";import{shippingMethodWriteData}from"../write-data";export async function store(data){try{const uuid=randomUUIDv7();const shippingData={...shippingMethodWriteData(data),uuid};await db.insertInto("shipping_methods").values(shippingData).executeTakeFirst();const model=await db.selectFrom("shipping_methods").where("uuid","=",uuid).selectAll().executeTakeFirst();if(!model)throw new Error("Failed to resolve created shipping method");return asModelRow(model)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create shipping method: ${error.message}`)}throw error}}export async function bulkStore(data){if(!data.length)return 0;try{const shippingDataArray=data.map((item)=>({...shippingMethodWriteData(item),uuid:randomUUIDv7()}));const result=await db.insertInto("shipping_methods").values(shippingDataArray).executeTakeFirst();return mutationCount(result)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to create shipping methods in bulk: ${error.message}`)}throw error}}export async function formatShippingOptions(){try{return await db.selectFrom("shipping_methods").select(["id","name","status","base_rate"]).orderBy("name").execute()}catch(error){if(error instanceof Error){throw new TypeError(`Failed to format shipping options: ${error.message}`)}throw error}}export async function getActiveShippingMethods(){try{const rows=await db.selectFrom("shipping_methods").selectAll().where("status","=","active").orderBy("name").execute();return asModelRows(rows)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to get active shipping methods: ${error.message}`)}throw error}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{db}from"@stacksjs/database/runtime";import{asModelRow,asModelRows}from"../../utils/model-row";export async function fetchAll(){return asModelRows(await db.selectFrom("shipping_zones").selectAll().execute())}export async function fetchById(id){const row=await db.selectFrom("shipping_zones").where("id","=",id).selectAll().executeTakeFirst();return asModelRow(row,true)}export function formatZoneOptions(){try{return db.selectFrom("shipping_zones").select(["id","name","status","countries"]).orderBy("name").execute()}catch(error){if(error instanceof Error){throw new TypeError(`Failed to format shipping zone options: ${error.message}`)}throw error}}export async function getActiveShippingZones(){try{const activeZones=await db.selectFrom("shipping_zones").selectAll().where("status","=","active").orderBy("name").execute();return asModelRows(activeZones)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to get active shipping zones: ${error.message}`)}throw error}}export async function getZonesByCountry(countryCode){try{const zones=await db.selectFrom("shipping_zones").selectAll().where("countries","like",`%${countryCode}%`).where("status","=","active").orderBy("name").execute();return asModelRows(zones)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to get shipping zones by country: ${error.message}`)}throw error}}
|
|
1
|
+
import{db}from"@stacksjs/database/runtime";import{asModelRow,asModelRows}from"../../utils/model-row";export async function fetchAll(){return asModelRows(await db.selectFrom("shipping_zones").selectAll().execute())}export async function fetchById(id){const row=await db.selectFrom("shipping_zones").where("id","=",id).selectAll().executeTakeFirst();return asModelRow(row,true)}export async function formatZoneOptions(){try{return await db.selectFrom("shipping_zones").select(["id","name","status","countries"]).orderBy("name").execute()}catch(error){if(error instanceof Error){throw new TypeError(`Failed to format shipping zone options: ${error.message}`)}throw error}}export async function getActiveShippingZones(){try{const activeZones=await db.selectFrom("shipping_zones").selectAll().where("status","=","active").orderBy("name").execute();return asModelRows(activeZones)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to get active shipping zones: ${error.message}`)}throw error}}export async function getZonesByCountry(countryCode){try{const zones=await db.selectFrom("shipping_zones").selectAll().where("countries","like",`%${countryCode}%`).where("status","=","active").orderBy("name").execute();return asModelRows(zones)}catch(error){if(error instanceof Error){throw new TypeError(`Failed to get shipping zones by country: ${error.message}`)}throw error}}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/commerce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.75.
|
|
4
|
+
"version": "0.75.571",
|
|
5
5
|
"description": "Stacks commerce utilities.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -57,19 +57,19 @@
|
|
|
57
57
|
"prepublishOnly": "bun run build"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@stacksjs/cache": "0.75.
|
|
61
|
-
"@stacksjs/config": "0.75.
|
|
62
|
-
"@stacksjs/database": "0.75.
|
|
63
|
-
"@stacksjs/env": "0.75.
|
|
64
|
-
"@stacksjs/error-handling": "0.75.
|
|
65
|
-
"@stacksjs/events": "0.75.
|
|
66
|
-
"@stacksjs/logging": "0.75.
|
|
67
|
-
"@stacksjs/orm": "0.75.
|
|
68
|
-
"@stacksjs/payments": "0.75.
|
|
69
|
-
"@stacksjs/realtime": "0.75.
|
|
70
|
-
"@stacksjs/slug": "0.75.
|
|
71
|
-
"@stacksjs/strings": "0.75.
|
|
72
|
-
"@stacksjs/validation": "0.75.
|
|
60
|
+
"@stacksjs/cache": "0.75.571",
|
|
61
|
+
"@stacksjs/config": "0.75.571",
|
|
62
|
+
"@stacksjs/database": "0.75.571",
|
|
63
|
+
"@stacksjs/env": "0.75.571",
|
|
64
|
+
"@stacksjs/error-handling": "0.75.571",
|
|
65
|
+
"@stacksjs/events": "0.75.571",
|
|
66
|
+
"@stacksjs/logging": "0.75.571",
|
|
67
|
+
"@stacksjs/orm": "0.75.571",
|
|
68
|
+
"@stacksjs/payments": "0.75.571",
|
|
69
|
+
"@stacksjs/realtime": "0.75.571",
|
|
70
|
+
"@stacksjs/slug": "0.75.571",
|
|
71
|
+
"@stacksjs/strings": "0.75.571",
|
|
72
|
+
"@stacksjs/validation": "0.75.571",
|
|
73
73
|
"ts-spreadsheets": "^0.2.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|