@eeplatform/core 1.3.0 → 1.4.1

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.
package/dist/index.mjs CHANGED
@@ -12840,7 +12840,7 @@ function useVerificationService() {
12840
12840
  mailer.sendMail({
12841
12841
  to: email,
12842
12842
  subject: "Forget Password",
12843
- from: "GoWeekdays",
12843
+ from: "EEPlatform",
12844
12844
  html: emailContent
12845
12845
  }).catch((error) => {
12846
12846
  logger4.log({
@@ -13035,7 +13035,7 @@ function useVerificationService() {
13035
13035
  to: email,
13036
13036
  subject: "Sign Up Verification",
13037
13037
  html: emailContent,
13038
- from: "GoWeekdays"
13038
+ from: "EEPlatform"
13039
13039
  }).catch((error) => {
13040
13040
  logger4.log({
13041
13041
  level: "error",
@@ -17120,7 +17120,7 @@ function useXenditService() {
17120
17120
  }
17121
17121
  },
17122
17122
  reusability: "MULTIPLE_USE",
17123
- description: "Linking card to GoWeekdays account."
17123
+ description: "Linking card to EEPlatform account."
17124
17124
  });
17125
17125
  return res.data;
17126
17126
  } catch (error) {
@@ -21539,13 +21539,13 @@ function usePaypalService() {
21539
21539
  name: {
21540
21540
  full_name: data.customerName
21541
21541
  },
21542
- website: "www.goweekdays.com"
21542
+ website: "www.eeplatform.org"
21543
21543
  },
21544
21544
  primary_recipients: [
21545
21545
  {
21546
21546
  billing_info: {
21547
21547
  name: {
21548
- full_name: data.customerName || "GoWeekdays Customer"
21548
+ full_name: data.customerName || "EEPlatform Customer"
21549
21549
  },
21550
21550
  email_address: data.customerEmail
21551
21551
  }
@@ -21608,7 +21608,7 @@ function usePaypalService() {
21608
21608
  await axios_default.post(
21609
21609
  `${PAYPAL_API_URL}/v2/invoicing/invoices/${invoiceId}/send`,
21610
21610
  {
21611
- subject: "GoWeekdays Monthly Invoice",
21611
+ subject: "EEPlatform Monthly Invoice",
21612
21612
  send_to_recipient: true,
21613
21613
  send_to_invoicer: false
21614
21614
  },
@@ -21705,7 +21705,7 @@ function useSubscriptionService() {
21705
21705
  totalCost += tierCost;
21706
21706
  nonProratedCost += seatsInTier * price;
21707
21707
  items.push({
21708
- description: `GoWeekdays Subscription - ${seatsInTier} seats @ ${price} per seat`,
21708
+ description: `EEPlatform Subscription - ${seatsInTier} seats @ ${price} per seat`,
21709
21709
  unitPrice: price,
21710
21710
  quantity: seatsInTier,
21711
21711
  seats: seatsInTier,
@@ -21763,7 +21763,7 @@ function useSubscriptionService() {
21763
21763
  session
21764
21764
  );
21765
21765
  }
21766
- const description = "GoWeekdays Organization Monthly Subscription.";
21766
+ const description = "EEPlatform Organization Monthly Subscription.";
21767
21767
  const monthlySubscriptionPrice = await getByNameType(
21768
21768
  "organization-subscription",
21769
21769
  "monthly-subscription"
@@ -21788,7 +21788,7 @@ function useSubscriptionService() {
21788
21788
  if (promoCode && promoCode.type === "fixed" && promoCode.fixed_rate !== void 0 && promoCode.fixed_rate >= 0) {
21789
21789
  amount = promoCode.fixed_rate;
21790
21790
  items.push({
21791
- description: "GoWeekdays Monthly Subscription",
21791
+ description: "EEPlatform Monthly Subscription",
21792
21792
  unitPrice: promoCode.fixed_rate,
21793
21793
  quantity: 1,
21794
21794
  seats: value.seats,
@@ -21847,7 +21847,7 @@ function useSubscriptionService() {
21847
21847
  status: "paid",
21848
21848
  items: items && items.length ? items : [
21849
21849
  {
21850
- description: "GoWeekdays Monthly Subscription",
21850
+ description: "EEPlatform Monthly Subscription",
21851
21851
  unitPrice: amount,
21852
21852
  quantity: 1,
21853
21853
  seats: value.seats,
@@ -21957,7 +21957,7 @@ function useSubscriptionService() {
21957
21957
  }
21958
21958
  value.billingAddress.org = orgId.toString();
21959
21959
  await addAddress(value.billingAddress, session);
21960
- const description = "GoWeekdays Organization Monthly Subscription.";
21960
+ const description = "EEPlatform Organization Monthly Subscription.";
21961
21961
  if (value.promoCode) {
21962
21962
  await assignByUserId(
21963
21963
  { user: value.user, code: value.promoCode },
@@ -21983,7 +21983,7 @@ function useSubscriptionService() {
21983
21983
  if (promoCode && promoCode.type === "fixed" && promoCode.fixed_rate !== void 0 && promoCode.fixed_rate >= 0) {
21984
21984
  amount = promoCode.fixed_rate;
21985
21985
  items.push({
21986
- description: "GoWeekdays Monthly Subscription",
21986
+ description: "EEPlatform Monthly Subscription",
21987
21987
  unitPrice: promoCode.fixed_rate,
21988
21988
  quantity: 1,
21989
21989
  seats: value.seats,
@@ -22043,7 +22043,7 @@ function useSubscriptionService() {
22043
22043
  status: "paid",
22044
22044
  items: items && items.length ? items : [
22045
22045
  {
22046
- description: "GoWeekdays Monthly Subscription",
22046
+ description: "EEPlatform Monthly Subscription",
22047
22047
  unitPrice: amount,
22048
22048
  quantity: 1,
22049
22049
  seats: value.seats,
@@ -22103,7 +22103,7 @@ function useSubscriptionService() {
22103
22103
  throw new BadRequestError33("User not found.");
22104
22104
  }
22105
22105
  await addAddress(value.billingAddress, session);
22106
- const description = "GoWeekdays affiliate yearly Subscription.";
22106
+ const description = "EEPlatform affiliate yearly Subscription.";
22107
22107
  const customer = await getCustomerById(value.customer_id);
22108
22108
  if (!customer.id) {
22109
22109
  throw new BadRequestError33("Xendit customer account required.");
@@ -22130,7 +22130,7 @@ function useSubscriptionService() {
22130
22130
  if (promoCode && promoCode.type === "fixed" && promoCode.fixed_rate !== void 0 && promoCode.fixed_rate >= 0) {
22131
22131
  amount = promoCode.fixed_rate;
22132
22132
  items.push({
22133
- description: "GoWeekdays Yearly Affiliate Subscription",
22133
+ description: "EEPlatform Yearly Affiliate Subscription",
22134
22134
  unitPrice: promoCode.fixed_rate,
22135
22135
  quantity: 1,
22136
22136
  seats: 1,
@@ -22178,7 +22178,7 @@ function useSubscriptionService() {
22178
22178
  status: "paid",
22179
22179
  items: items.length ? items : [
22180
22180
  {
22181
- description: "GoWeekdays Yearly Affiliate Subscription",
22181
+ description: "EEPlatform Yearly Affiliate Subscription",
22182
22182
  unitPrice: amount,
22183
22183
  quantity: 1,
22184
22184
  seats: 1,
@@ -22279,7 +22279,7 @@ function useSubscriptionService() {
22279
22279
  }
22280
22280
  const promoCode = await getByCode(code).catch(() => null);
22281
22281
  let amount = price.value * chargeableSeats;
22282
- const description = `GoWeekdays ${sub.type} ${sub.billingCycle} Subscription`;
22282
+ const description = `EEPlatform ${sub.type} ${sub.billingCycle} Subscription`;
22283
22283
  const items = [];
22284
22284
  if (code && promoCode && promoCode.type === "fixed" && promoCode.fixed_rate !== void 0 && promoCode.fixed_rate >= 0) {
22285
22285
  amount = promoCode.fixed_rate * chargeableSeats;
@@ -22456,7 +22456,7 @@ function useSubscriptionService() {
22456
22456
  newMonthSubscriptionFee = formatAmount(perSeatPrice * seats);
22457
22457
  items = [
22458
22458
  {
22459
- description: `GoWeekdays Subscription - ${seats} seats @ ${perSeatPrice} per seat`,
22459
+ description: `EEPlatform Subscription - ${seats} seats @ ${perSeatPrice} per seat`,
22460
22460
  unitPrice: perSeatPrice,
22461
22461
  quantity: 1,
22462
22462
  seats,
@@ -22619,7 +22619,7 @@ function useSubscriptionService() {
22619
22619
  status: "paid",
22620
22620
  items: [
22621
22621
  {
22622
- description: "GoWeekdays Monthly Subscription",
22622
+ description: "EEPlatform Monthly Subscription",
22623
22623
  unitPrice: formatAmount(perSeatPrice),
22624
22624
  quantity: 1,
22625
22625
  seats,
@@ -22640,7 +22640,7 @@ function useSubscriptionService() {
22640
22640
  payment_method_id: subscription.paymentMethodId ?? "",
22641
22641
  amount: formatAmount(amount),
22642
22642
  currency: subscription.currency,
22643
- description: "GoWeekdays Organization Monthly Subscription."
22643
+ description: "EEPlatform Organization Monthly Subscription."
22644
22644
  });
22645
22645
  }
22646
22646
  const paymentMethod = await getPaymentMethodById(
@@ -22830,7 +22830,7 @@ function useSubscriptionService() {
22830
22830
  status: "paid",
22831
22831
  items: [
22832
22832
  {
22833
- description: "GoWeekdays Monthly Subscription",
22833
+ description: "EEPlatform Monthly Subscription",
22834
22834
  unitPrice: formatAmount(perSeatPrice),
22835
22835
  quantity: 1,
22836
22836
  seats,
@@ -22966,7 +22966,7 @@ function useSubscriptionService() {
22966
22966
  payment_method_id: subscription.paymentMethodId,
22967
22967
  amount: subscription.amount,
22968
22968
  currency: subscription.currency,
22969
- description: "GoWeekdays Subscription Payment"
22969
+ description: "EEPlatform Subscription Payment"
22970
22970
  });
22971
22971
  if (!payment.id) {
22972
22972
  throw new BadRequestError33("Failed to process payment.");
@@ -27782,7 +27782,7 @@ import Joi34 from "joi";
27782
27782
  // src/services/building.service.ts
27783
27783
  import {
27784
27784
  BadRequestError as BadRequestError62,
27785
- NotFoundError as NotFoundError11,
27785
+ NotFoundError as NotFoundError10,
27786
27786
  useAtlas as useAtlas33
27787
27787
  } from "@eeplatform/nodejs-utils";
27788
27788
  function useBuildingService() {
@@ -27798,7 +27798,7 @@ function useBuildingService() {
27798
27798
  try {
27799
27799
  const building = await _getById(id);
27800
27800
  if (!building) {
27801
- throw new NotFoundError11("Building not found.");
27801
+ throw new NotFoundError10("Building not found.");
27802
27802
  }
27803
27803
  if (data.levels < building.levels) {
27804
27804
  const unit = await getByBuildingLevel(id, building.levels);
@@ -28177,19 +28177,19 @@ function useBuildingUnitController() {
28177
28177
  };
28178
28178
  }
28179
28179
 
28180
- // src/models/inventory.model.ts
28180
+ // src/models/asset.model.ts
28181
28181
  import { BadRequestError as BadRequestError65 } from "@eeplatform/nodejs-utils";
28182
28182
  import Joi36 from "joi";
28183
28183
  import { ObjectId as ObjectId42 } from "mongodb";
28184
- var schemaInventory = Joi36.object({
28184
+ var schemaAsset = Joi36.object({
28185
28185
  _id: Joi36.string().hex().optional(),
28186
28186
  school: Joi36.string().hex().required(),
28187
+ asset_type: Joi36.string().required().allow("supply", "furniture-equipment", "fixed-asset"),
28187
28188
  name: Joi36.string().required(),
28188
28189
  category: Joi36.string().optional().allow("", null),
28189
28190
  type: Joi36.string().optional().allow("", null),
28190
28191
  brand: Joi36.string().optional().allow("", null),
28191
- unit_of_measurement_category: Joi36.string().required(),
28192
- unit_of_measurement_type: Joi36.string().required(),
28192
+ unit: Joi36.string().required(),
28193
28193
  status: Joi36.string().optional().allow("", null),
28194
28194
  createdAt: Joi36.date().optional().allow("", null),
28195
28195
  updatedAt: Joi36.date().optional().allow("", null),
@@ -28205,14 +28205,13 @@ var schemaInventory = Joi36.object({
28205
28205
  language: Joi36.string().optional().allow("", null)
28206
28206
  }).optional().allow(null)
28207
28207
  });
28208
- var schemaInventoryUpdateOption = Joi36.object({
28208
+ var schemaAssetUpdateOption = Joi36.object({
28209
28209
  name: Joi36.string().optional().allow("", null),
28210
28210
  category: Joi36.string().optional().allow("", null),
28211
28211
  type: Joi36.string().optional().allow("", null),
28212
28212
  brand: Joi36.string().optional().allow("", null),
28213
28213
  qty: Joi36.number().integer().min(0).optional().allow("", null),
28214
- unit_of_measurement_category: Joi36.string().optional().allow("", null),
28215
- unit_of_measurement_type: Joi36.string().optional().allow("", null),
28214
+ unit: Joi36.string().optional().allow("", null),
28216
28215
  metadata: Joi36.object({
28217
28216
  title: Joi36.string().optional().allow("", null),
28218
28217
  isbn: Joi36.string().optional().allow("", null),
@@ -28224,8 +28223,8 @@ var schemaInventoryUpdateOption = Joi36.object({
28224
28223
  language: Joi36.string().optional().allow("", null)
28225
28224
  }).optional().allow(null)
28226
28225
  });
28227
- function MInventory(value) {
28228
- const { error } = schemaInventory.validate(value);
28226
+ function MAsset(value) {
28227
+ const { error } = schemaAsset.validate(value);
28229
28228
  if (error) {
28230
28229
  throw new BadRequestError65(error.message);
28231
28230
  }
@@ -28247,6 +28246,7 @@ function MInventory(value) {
28247
28246
  return {
28248
28247
  _id: value._id ?? new ObjectId42(),
28249
28248
  school: value.school,
28249
+ asset_type: value.asset_type ?? "supply",
28250
28250
  name: value.name,
28251
28251
  category: value.category ?? "",
28252
28252
  type: value.type ?? "",
@@ -28258,8 +28258,7 @@ function MInventory(value) {
28258
28258
  lost: 0,
28259
28259
  damaged: 0
28260
28260
  },
28261
- unit_of_measurement_category: value.unit_of_measurement_category ?? "",
28262
- unit_of_measurement_type: value.unit_of_measurement_type ?? "",
28261
+ unit: value.unit ?? "",
28263
28262
  status: value.status ?? "active",
28264
28263
  createdAt: value.createdAt,
28265
28264
  updatedAt: value.updatedAt,
@@ -28268,7 +28267,7 @@ function MInventory(value) {
28268
28267
  };
28269
28268
  }
28270
28269
 
28271
- // src/repositories/inventory.repository.ts
28270
+ // src/repositories/asset.repository.ts
28272
28271
  import {
28273
28272
  BadRequestError as BadRequestError66,
28274
28273
  logger as logger33,
@@ -28278,12 +28277,12 @@ import {
28278
28277
  useCache as useCache22
28279
28278
  } from "@eeplatform/nodejs-utils";
28280
28279
  import { ObjectId as ObjectId43 } from "mongodb";
28281
- function useInventoryRepo() {
28280
+ function useAssetRepo() {
28282
28281
  const db = useAtlas35.getDb();
28283
28282
  if (!db) {
28284
28283
  throw new BadRequestError66("Unable to connect to server.");
28285
28284
  }
28286
- const namespace_collection = "school.inventories";
28285
+ const namespace_collection = "school.assets";
28287
28286
  const collection = db.collection(namespace_collection);
28288
28287
  const { getCache, setCache, delNamespace } = useCache22(namespace_collection);
28289
28288
  function delCachedData() {
@@ -28307,21 +28306,21 @@ function useInventoryRepo() {
28307
28306
  { key: { name: "text" } }
28308
28307
  ]);
28309
28308
  } catch (error) {
28310
- throw new BadRequestError66("Failed to create index on inventory.");
28309
+ throw new BadRequestError66("Failed to create index on asset.");
28311
28310
  }
28312
28311
  }
28313
28312
  async function add(value) {
28314
28313
  try {
28315
- value = MInventory(value);
28314
+ value = MAsset(value);
28316
28315
  const res = await collection.insertOne(value);
28317
28316
  delCachedData();
28318
28317
  return res.insertedId;
28319
28318
  } catch (error) {
28320
- throw new BadRequestError66("Failed to create inventory item.");
28319
+ throw new BadRequestError66("Failed to create asset item.");
28321
28320
  }
28322
28321
  }
28323
- async function updateById(_id, value) {
28324
- const { error } = schemaInventoryUpdateOption.validate(value);
28322
+ async function updateById(_id, value, session) {
28323
+ const { error } = schemaAssetUpdateOption.validate(value);
28325
28324
  if (error) {
28326
28325
  throw new BadRequestError66(error.message);
28327
28326
  }
@@ -28331,13 +28330,17 @@ function useInventoryRepo() {
28331
28330
  throw new BadRequestError66("Invalid ID.");
28332
28331
  }
28333
28332
  try {
28334
- const res = await collection.updateOne({ _id }, { $set: value });
28333
+ const res = await collection.updateOne(
28334
+ { _id },
28335
+ { $set: value },
28336
+ { session }
28337
+ );
28335
28338
  if (res.modifiedCount) {
28336
28339
  delCachedData();
28337
28340
  }
28338
- return "Successfully updated inventory item.";
28341
+ return "Successfully updated asset item.";
28339
28342
  } catch (error2) {
28340
- throw new BadRequestError66("Failed to update inventory item.");
28343
+ throw new BadRequestError66("Failed to update asset item.");
28341
28344
  }
28342
28345
  }
28343
28346
  async function deleteById(_id) {
@@ -28350,11 +28353,11 @@ function useInventoryRepo() {
28350
28353
  const res = await collection.deleteOne({ _id });
28351
28354
  if (res.deletedCount) {
28352
28355
  delCachedData();
28353
- return "Successfully deleted inventory item.";
28356
+ return "Successfully deleted asset item.";
28354
28357
  }
28355
- return "Successfully deleted inventory item.";
28358
+ return "Successfully deleted asset item.";
28356
28359
  } catch (error) {
28357
- throw new BadRequestError66("Failed to delete inventory item.");
28360
+ throw new BadRequestError66("Failed to delete asset item.");
28358
28361
  }
28359
28362
  }
28360
28363
  async function getById(_id) {
@@ -28371,17 +28374,17 @@ function useInventoryRepo() {
28371
28374
  try {
28372
28375
  const res = await collection.findOne({ _id });
28373
28376
  if (!res) {
28374
- throw new BadRequestError66("Inventory item not found.");
28377
+ throw new BadRequestError66("Asset item not found.");
28375
28378
  }
28376
28379
  setCache(cacheKey, res).then(() => {
28377
28380
  logger33.log({
28378
28381
  level: "info",
28379
- message: `Cache set for inventory item by ID: ${cacheKey}`
28382
+ message: `Cache set for asset item by ID: ${cacheKey}`
28380
28383
  });
28381
28384
  }).catch((err) => {
28382
28385
  logger33.log({
28383
28386
  level: "error",
28384
- message: `Failed to set cache for inventory item by ID: ${cacheKey} - ${err.message}`
28387
+ message: `Failed to set cache for asset item by ID: ${cacheKey} - ${err.message}`
28385
28388
  });
28386
28389
  });
28387
28390
  return res;
@@ -28389,7 +28392,7 @@ function useInventoryRepo() {
28389
28392
  if (error instanceof BadRequestError66) {
28390
28393
  throw error;
28391
28394
  }
28392
- throw new BadRequestError66("Failed to retrieve inventory item.");
28395
+ throw new BadRequestError66("Failed to retrieve asset item.");
28393
28396
  }
28394
28397
  }
28395
28398
  async function getAll({
@@ -28398,7 +28401,8 @@ function useInventoryRepo() {
28398
28401
  limit = 20,
28399
28402
  status = "active",
28400
28403
  school = "",
28401
- sort = { _id: -1 }
28404
+ sort = { _id: -1 },
28405
+ asset_type = "supply"
28402
28406
  } = {}) {
28403
28407
  page = page ? page - 1 : 0;
28404
28408
  try {
@@ -28408,14 +28412,16 @@ function useInventoryRepo() {
28408
28412
  }
28409
28413
  const query = {
28410
28414
  school,
28411
- status
28415
+ status,
28416
+ asset_type
28412
28417
  };
28413
28418
  const cacheKeyOptions = {
28414
28419
  page,
28415
28420
  limit,
28416
28421
  status,
28417
28422
  school: String(school),
28418
- sort: JSON.stringify(sort)
28423
+ sort: JSON.stringify(sort),
28424
+ asset_type
28419
28425
  };
28420
28426
  if (search) {
28421
28427
  query.$text = { $search: search };
@@ -28427,7 +28433,7 @@ function useInventoryRepo() {
28427
28433
  if (cached) {
28428
28434
  logger33.log({
28429
28435
  level: "info",
28430
- message: `Cache hit for getAll inventory items: ${cacheKey}`
28436
+ message: `Cache hit for getAll asset items: ${cacheKey}`
28431
28437
  });
28432
28438
  return cached;
28433
28439
  }
@@ -28448,18 +28454,194 @@ function useInventoryRepo() {
28448
28454
  setCache(cacheKey, data, 500).then(() => {
28449
28455
  logger33.log({
28450
28456
  level: "info",
28451
- message: `Cache set for getAll inventory items: ${cacheKey}`
28457
+ message: `Cache set for getAll asset items: ${cacheKey}`
28452
28458
  });
28453
28459
  }).catch((err) => {
28454
28460
  logger33.log({
28455
28461
  level: "error",
28456
- message: `Failed to set cache for getAll inventory items: ${err.message}`
28462
+ message: `Failed to set cache for getAll asset items: ${err.message}`
28457
28463
  });
28458
28464
  });
28459
28465
  return data;
28460
28466
  } catch (error) {
28461
28467
  console.log("Error in getAll:", error);
28462
- throw new BadRequestError66("Failed to retrieve inventory items.");
28468
+ throw new BadRequestError66("Failed to retrieve asset items.");
28469
+ }
28470
+ }
28471
+ async function getCategories(school, asset_type) {
28472
+ try {
28473
+ school = new ObjectId43(school);
28474
+ } catch (error) {
28475
+ throw new BadRequestError66("Invalid school ID.");
28476
+ }
28477
+ const cacheKey = makeCacheKey21(namespace_collection, {
28478
+ school,
28479
+ asset_type,
28480
+ type: "category-as-options"
28481
+ });
28482
+ const cachedData = await getCache(cacheKey);
28483
+ if (cachedData) {
28484
+ return cachedData;
28485
+ }
28486
+ try {
28487
+ const categories = await collection.aggregate([
28488
+ {
28489
+ $match: { school, asset_type }
28490
+ },
28491
+ {
28492
+ $group: {
28493
+ _id: "$category",
28494
+ value: { $first: "$category" },
28495
+ title: {
28496
+ $first: "$category"
28497
+ }
28498
+ }
28499
+ },
28500
+ {
28501
+ $project: {
28502
+ _id: 0,
28503
+ title: 1,
28504
+ value: 1
28505
+ }
28506
+ },
28507
+ { $sort: { title: 1 } }
28508
+ ]).toArray();
28509
+ setCache(cacheKey, categories).then(() => {
28510
+ logger33.log({
28511
+ level: "info",
28512
+ message: `Cache set for getCategoriesBySchool: ${cacheKey}`
28513
+ });
28514
+ }).catch((err) => {
28515
+ logger33.log({
28516
+ level: "error",
28517
+ message: `Failed to set cache for getCategoriesBySchool: ${err.message}`
28518
+ });
28519
+ });
28520
+ return categories;
28521
+ } catch (error) {
28522
+ if (error instanceof BadRequestError66) {
28523
+ throw error;
28524
+ }
28525
+ throw new BadRequestError66("Failed to retrieve asset categories.");
28526
+ }
28527
+ }
28528
+ async function getTypes(school, asset_type) {
28529
+ try {
28530
+ school = new ObjectId43(school);
28531
+ } catch (error) {
28532
+ throw new BadRequestError66("Invalid school ID.");
28533
+ }
28534
+ const cacheKey = makeCacheKey21(namespace_collection, {
28535
+ school,
28536
+ asset_type,
28537
+ type: "types-as-options"
28538
+ });
28539
+ const cachedData = await getCache(cacheKey);
28540
+ if (cachedData) {
28541
+ return cachedData;
28542
+ }
28543
+ try {
28544
+ const categories = await collection.aggregate([
28545
+ {
28546
+ $match: { school, asset_type }
28547
+ },
28548
+ {
28549
+ $group: {
28550
+ _id: "$type",
28551
+ value: { $first: "$type" },
28552
+ category: { $first: "$category" },
28553
+ title: { $first: "$name" },
28554
+ subtitle: { $first: "" }
28555
+ // keep empty for now, can be filled later
28556
+ }
28557
+ },
28558
+ {
28559
+ $project: {
28560
+ _id: 0,
28561
+ title: 1,
28562
+ value: 1,
28563
+ category: 1,
28564
+ subtitle: 1
28565
+ }
28566
+ },
28567
+ { $sort: { title: 1 } }
28568
+ ]).toArray();
28569
+ setCache(cacheKey, categories).then(() => {
28570
+ logger33.log({
28571
+ level: "info",
28572
+ message: `Cache set for getCategoriesBySchool: ${cacheKey}`
28573
+ });
28574
+ }).catch((err) => {
28575
+ logger33.log({
28576
+ level: "error",
28577
+ message: `Failed to set cache for getCategoriesBySchool: ${err.message}`
28578
+ });
28579
+ });
28580
+ return categories;
28581
+ } catch (error) {
28582
+ if (error instanceof BadRequestError66) {
28583
+ throw error;
28584
+ }
28585
+ throw new BadRequestError66("Failed to retrieve asset categories.");
28586
+ }
28587
+ }
28588
+ async function getUnitsBySchool(school) {
28589
+ try {
28590
+ school = new ObjectId43(school);
28591
+ } catch (error) {
28592
+ throw new BadRequestError66("Invalid school ID.");
28593
+ }
28594
+ const cacheKey = makeCacheKey21(namespace_collection, {
28595
+ school,
28596
+ type: "unit-as-options"
28597
+ });
28598
+ const cachedData = await getCache(cacheKey);
28599
+ if (cachedData) {
28600
+ return cachedData;
28601
+ }
28602
+ try {
28603
+ const categories = await collection.aggregate([
28604
+ {
28605
+ $match: { school }
28606
+ },
28607
+ {
28608
+ $group: {
28609
+ _id: "$unit",
28610
+ value: { $first: "$unit" },
28611
+ title: {
28612
+ $first: "$unit"
28613
+ }
28614
+ }
28615
+ },
28616
+ {
28617
+ $project: {
28618
+ _id: 0,
28619
+ title: 1,
28620
+ value: 1
28621
+ }
28622
+ },
28623
+ { $sort: { title: 1 } }
28624
+ ]).toArray();
28625
+ setCache(cacheKey, categories).then(() => {
28626
+ logger33.log({
28627
+ level: "info",
28628
+ message: `Cache set for getUnitBy: ${cacheKey}`
28629
+ });
28630
+ }).catch((err) => {
28631
+ logger33.log({
28632
+ level: "error",
28633
+ message: `Failed to set cache for getUnitBy: ${err.message}`
28634
+ });
28635
+ });
28636
+ return categories;
28637
+ } catch (error) {
28638
+ console.log(error);
28639
+ if (error instanceof BadRequestError66) {
28640
+ throw error;
28641
+ }
28642
+ throw new BadRequestError66(
28643
+ "Failed to retrieve asset unit of measurements."
28644
+ );
28463
28645
  }
28464
28646
  }
28465
28647
  return {
@@ -28468,30 +28650,37 @@ function useInventoryRepo() {
28468
28650
  updateById,
28469
28651
  deleteById,
28470
28652
  getById,
28471
- getAll
28653
+ getAll,
28654
+ getCategories,
28655
+ getTypes,
28656
+ getUnitsBySchool
28472
28657
  };
28473
28658
  }
28474
28659
 
28475
- // src/controllers/inventory.controller.ts
28660
+ // src/controllers/asset.controller.ts
28476
28661
  import { BadRequestError as BadRequestError67 } from "@eeplatform/nodejs-utils";
28477
28662
  import Joi37 from "joi";
28478
- function useInventoryController() {
28663
+ function useAssetController() {
28479
28664
  const {
28480
28665
  add: _add,
28481
28666
  getAll: _getAll,
28482
28667
  deleteById: _deleteById,
28483
- updateById: _updateById
28484
- } = useInventoryRepo();
28668
+ updateById: _updateById,
28669
+ getById: _getById,
28670
+ getCategories: _getCategories,
28671
+ getTypes: _getTypes,
28672
+ getUnitsBySchool: _getUnitsBySchool
28673
+ } = useAssetRepo();
28485
28674
  async function add(req, res, next) {
28486
28675
  const value = req.body;
28487
- const { error } = schemaInventory.validate(value);
28676
+ const { error } = schemaAsset.validate(value);
28488
28677
  if (error) {
28489
28678
  next(new BadRequestError67(error.message));
28490
28679
  return;
28491
28680
  }
28492
28681
  try {
28493
28682
  const id = await _add(value);
28494
- res.json({ message: "Successfully added inventory item.", id });
28683
+ res.json({ message: "Successfully added asset item.", id });
28495
28684
  } catch (error2) {
28496
28685
  next(error2);
28497
28686
  }
@@ -28503,7 +28692,8 @@ function useInventoryController() {
28503
28692
  limit: Joi37.number().min(1).optional().allow("", null),
28504
28693
  search: Joi37.string().optional().allow("", null),
28505
28694
  status: Joi37.string().optional().allow("", null),
28506
- school: Joi37.string().hex().optional().allow("", null)
28695
+ school: Joi37.string().hex().optional().allow("", null),
28696
+ asset_type: Joi37.string().required().allow("supply", "furniture-equipment", "fixed-asset")
28507
28697
  });
28508
28698
  const { error } = validation.validate(query);
28509
28699
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -28511,6 +28701,7 @@ function useInventoryController() {
28511
28701
  const search = req.query.search ?? "";
28512
28702
  const status = req.query.status ?? "active";
28513
28703
  const school = req.query.school ?? "";
28704
+ const asset_type = req.query.asset_type ?? "supply";
28514
28705
  const isPageNumber = isFinite(page);
28515
28706
  if (!isPageNumber) {
28516
28707
  next(new BadRequestError67("Invalid page number."));
@@ -28526,7 +28717,14 @@ function useInventoryController() {
28526
28717
  return;
28527
28718
  }
28528
28719
  try {
28529
- const regions = await _getAll({ page, limit, search, status, school });
28720
+ const regions = await _getAll({
28721
+ page,
28722
+ limit,
28723
+ search,
28724
+ status,
28725
+ school,
28726
+ asset_type
28727
+ });
28530
28728
  res.json(regions);
28531
28729
  return;
28532
28730
  } catch (error2) {
@@ -28543,7 +28741,22 @@ function useInventoryController() {
28543
28741
  }
28544
28742
  try {
28545
28743
  await _deleteById(id);
28546
- res.json({ message: "Successfully deleted inventory item.", id });
28744
+ res.json({ message: "Successfully deleted asset item.", id });
28745
+ } catch (error2) {
28746
+ next(error2);
28747
+ }
28748
+ }
28749
+ async function getById(req, res, next) {
28750
+ const id = req.params.id;
28751
+ const validation = Joi37.string().hex().required();
28752
+ const { error } = validation.validate(id);
28753
+ if (error) {
28754
+ next(new BadRequestError67(error.message));
28755
+ return;
28756
+ }
28757
+ try {
28758
+ const data = await _getById(id);
28759
+ res.json(data);
28547
28760
  } catch (error2) {
28548
28761
  next(error2);
28549
28762
  }
@@ -28551,14 +28764,61 @@ function useInventoryController() {
28551
28764
  async function updateById(req, res, next) {
28552
28765
  const id = req.params.id;
28553
28766
  const value = req.body;
28554
- const { error } = schemaInventoryUpdateOption.validate(value);
28767
+ const { error } = schemaAssetUpdateOption.validate(value);
28555
28768
  if (error) {
28556
28769
  next(new BadRequestError67(error.message));
28557
28770
  return;
28558
28771
  }
28559
28772
  try {
28560
28773
  await _updateById(id, value);
28561
- res.json({ message: "Successfully updated inventory item.", id });
28774
+ res.json({ message: "Successfully updated asset item.", id });
28775
+ } catch (error2) {
28776
+ next(error2);
28777
+ }
28778
+ }
28779
+ async function getCategories(req, res, next) {
28780
+ const school = req.params.school;
28781
+ const asset_type = req.params.asset_type;
28782
+ const validation = Joi37.string().hex().required();
28783
+ const { error } = validation.validate(school);
28784
+ if (error) {
28785
+ next(new BadRequestError67(error.message));
28786
+ return;
28787
+ }
28788
+ try {
28789
+ const data = await _getCategories(school, asset_type);
28790
+ res.json(data);
28791
+ } catch (error2) {
28792
+ next(error2);
28793
+ }
28794
+ }
28795
+ async function getTypes(req, res, next) {
28796
+ const school = req.params.school;
28797
+ const asset_type = req.params.asset_type;
28798
+ const validation = Joi37.string().hex().required();
28799
+ const { error } = validation.validate(school);
28800
+ if (error) {
28801
+ next(new BadRequestError67(error.message));
28802
+ return;
28803
+ }
28804
+ try {
28805
+ const data = await _getTypes(school, asset_type);
28806
+ res.json(data);
28807
+ } catch (error2) {
28808
+ next(error2);
28809
+ }
28810
+ }
28811
+ async function getUnitsBySchool(req, res, next) {
28812
+ const school = req.params.school;
28813
+ const validation = Joi37.string().hex().required();
28814
+ const { error } = validation.validate(school);
28815
+ if (error) {
28816
+ next(new BadRequestError67(error.message));
28817
+ return;
28818
+ }
28819
+ try {
28820
+ const data = await _getUnitsBySchool(school);
28821
+ res.json(data);
28562
28822
  } catch (error2) {
28563
28823
  next(error2);
28564
28824
  }
@@ -28567,7 +28827,433 @@ function useInventoryController() {
28567
28827
  add,
28568
28828
  getAll,
28569
28829
  deleteById,
28570
- updateById
28830
+ updateById,
28831
+ getById,
28832
+ getCategories,
28833
+ getTypes,
28834
+ getUnitsBySchool
28835
+ };
28836
+ }
28837
+
28838
+ // src/models/stock-card.model.ts
28839
+ import { BadRequestError as BadRequestError68 } from "@eeplatform/nodejs-utils";
28840
+ import Joi38 from "joi";
28841
+ import { ObjectId as ObjectId44 } from "mongodb";
28842
+ var schemaStockCard = Joi38.object({
28843
+ _id: Joi38.string().hex().optional().allow("", null),
28844
+ school: Joi38.string().hex().required(),
28845
+ item: Joi38.string().hex().required(),
28846
+ balance: Joi38.number().optional().allow(null, 0),
28847
+ qty: Joi38.number().required(),
28848
+ unitCost: Joi38.number().optional().allow(null, 0),
28849
+ totalCost: Joi38.number().optional().allow(null, 0),
28850
+ status: Joi38.string().optional().allow(null, ""),
28851
+ condition: Joi38.string().required(),
28852
+ supplier: Joi38.string().optional().allow("", null),
28853
+ location: Joi38.string().optional().allow("", null),
28854
+ locationName: Joi38.string().optional().allow("", null),
28855
+ reason: Joi38.string().optional().allow("", null),
28856
+ remarks: Joi38.string().optional().allow("", null),
28857
+ createdAt: Joi38.date().optional().allow("", null),
28858
+ updatedAt: Joi38.date().optional().allow("", null),
28859
+ deletedAt: Joi38.date().optional().allow("", null)
28860
+ });
28861
+ function MStockCard(value) {
28862
+ const { error } = schemaStockCard.validate(value);
28863
+ if (error) {
28864
+ throw new BadRequestError68(`Invalid stock card data: ${error.message}`);
28865
+ }
28866
+ if (value._id && typeof value._id === "string") {
28867
+ try {
28868
+ value._id = new ObjectId44(value._id);
28869
+ } catch (err) {
28870
+ throw new BadRequestError68("Invalid stock card ID.");
28871
+ }
28872
+ }
28873
+ try {
28874
+ value.item = new ObjectId44(value.item);
28875
+ } catch (err) {
28876
+ throw new BadRequestError68("Invalid item ID.");
28877
+ }
28878
+ try {
28879
+ value.school = new ObjectId44(value.school);
28880
+ } catch (err) {
28881
+ throw new BadRequestError68("Invalid school ID.");
28882
+ }
28883
+ return {
28884
+ _id: value._id ?? void 0,
28885
+ school: value.school,
28886
+ item: value.item,
28887
+ balance: value.balance,
28888
+ qty: value.qty,
28889
+ unitCost: value.unitCost,
28890
+ totalCost: value.totalCost,
28891
+ status: value.status ?? "in stock",
28892
+ condition: value.condition,
28893
+ supplier: value.supplier ?? "",
28894
+ location: value.location ?? void 0,
28895
+ locationName: value.locationName ?? "",
28896
+ reason: value.reason ?? "",
28897
+ remarks: value.remarks ?? "",
28898
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
28899
+ updatedAt: value.updatedAt ?? "",
28900
+ deletedAt: value.deletedAt ?? ""
28901
+ };
28902
+ }
28903
+
28904
+ // src/repositories/stock-card.repository.ts
28905
+ import {
28906
+ BadRequestError as BadRequestError69,
28907
+ logger as logger34,
28908
+ makeCacheKey as makeCacheKey22,
28909
+ paginate as paginate18,
28910
+ useAtlas as useAtlas36,
28911
+ useCache as useCache23
28912
+ } from "@eeplatform/nodejs-utils";
28913
+ import { ObjectId as ObjectId45 } from "mongodb";
28914
+ function useStockCardRepository() {
28915
+ const db = useAtlas36.getDb();
28916
+ if (!db) {
28917
+ throw new BadRequestError69("Unable to connect to server.");
28918
+ }
28919
+ const namespace_collection = "school.assets.stock-cards";
28920
+ const collection = db.collection(namespace_collection);
28921
+ const { getCache, setCache, delNamespace } = useCache23(namespace_collection);
28922
+ function delCachedData() {
28923
+ delNamespace().then(() => {
28924
+ logger34.log({
28925
+ level: "info",
28926
+ message: `Cache namespace cleared for ${namespace_collection}`
28927
+ });
28928
+ }).catch((err) => {
28929
+ logger34.log({
28930
+ level: "error",
28931
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
28932
+ });
28933
+ });
28934
+ }
28935
+ async function createIndex() {
28936
+ try {
28937
+ await collection.createIndexes([
28938
+ { key: { school: 1 } },
28939
+ { key: { item: 1 } }
28940
+ ]);
28941
+ } catch (error) {
28942
+ throw new BadRequestError69("Failed to create index on stock card.");
28943
+ }
28944
+ }
28945
+ async function add(value, session) {
28946
+ try {
28947
+ value = MStockCard(value);
28948
+ const res = await collection.insertOne(value, { session });
28949
+ delCachedData();
28950
+ return res.insertedId;
28951
+ } catch (error) {
28952
+ throw new BadRequestError69("Failed to create stock card.");
28953
+ }
28954
+ }
28955
+ async function getById(_id) {
28956
+ try {
28957
+ _id = new ObjectId45(_id);
28958
+ } catch (error) {
28959
+ throw new BadRequestError69("Invalid ID.");
28960
+ }
28961
+ const cacheKey = makeCacheKey22(namespace_collection, { _id: String(_id) });
28962
+ const cachedData = await getCache(cacheKey);
28963
+ if (cachedData) {
28964
+ return cachedData;
28965
+ }
28966
+ try {
28967
+ const res = await collection.findOne({ _id });
28968
+ if (!res) {
28969
+ throw new BadRequestError69("Asset item not found.");
28970
+ }
28971
+ setCache(cacheKey, res).then(() => {
28972
+ logger34.log({
28973
+ level: "info",
28974
+ message: `Cache set for stock card by ID: ${cacheKey}`
28975
+ });
28976
+ }).catch((err) => {
28977
+ logger34.log({
28978
+ level: "error",
28979
+ message: `Failed to set cache for stock card by ID: ${cacheKey} - ${err.message}`
28980
+ });
28981
+ });
28982
+ return res;
28983
+ } catch (error) {
28984
+ if (error instanceof BadRequestError69) {
28985
+ throw error;
28986
+ }
28987
+ throw new BadRequestError69("Failed to retrieve stock card.");
28988
+ }
28989
+ }
28990
+ async function getAll({ page = 1, limit = 20, school = "", sort = { _id: 1 }, id = "" } = {}) {
28991
+ page = page ? page - 1 : 0;
28992
+ try {
28993
+ school = new ObjectId45(school);
28994
+ } catch (error) {
28995
+ throw new BadRequestError69("Invalid school ID.");
28996
+ }
28997
+ try {
28998
+ id = new ObjectId45(id);
28999
+ } catch (error) {
29000
+ throw new BadRequestError69("Invalid ID.");
29001
+ }
29002
+ const query = {
29003
+ school,
29004
+ item: id
29005
+ };
29006
+ const cacheKeyOptions = {
29007
+ page,
29008
+ limit,
29009
+ school: String(school),
29010
+ sort: JSON.stringify(sort),
29011
+ item: id
29012
+ };
29013
+ try {
29014
+ const cacheKey = makeCacheKey22(namespace_collection, cacheKeyOptions);
29015
+ const cached = await getCache(cacheKey);
29016
+ if (cached) {
29017
+ logger34.log({
29018
+ level: "info",
29019
+ message: `Cache hit for getAll stock cards: ${cacheKey}`
29020
+ });
29021
+ return cached;
29022
+ }
29023
+ const items = await collection.aggregate([
29024
+ { $match: query },
29025
+ {
29026
+ $sort: sort
29027
+ },
29028
+ {
29029
+ $skip: page * limit
29030
+ },
29031
+ {
29032
+ $limit: limit
29033
+ }
29034
+ ]).toArray();
29035
+ const length = await collection.countDocuments(query);
29036
+ const data = paginate18(items, page, limit, length);
29037
+ setCache(cacheKey, data, 500).then(() => {
29038
+ logger34.log({
29039
+ level: "info",
29040
+ message: `Cache set for getAll stock cards: ${cacheKey}`
29041
+ });
29042
+ }).catch((err) => {
29043
+ logger34.log({
29044
+ level: "error",
29045
+ message: `Failed to set cache for getAll stock cards: ${err.message}`
29046
+ });
29047
+ });
29048
+ return data;
29049
+ } catch (error) {
29050
+ console.log("Error in getAll:", error);
29051
+ throw new BadRequestError69("Failed to retrieve stock cards.");
29052
+ }
29053
+ }
29054
+ async function getSuppliers(school) {
29055
+ try {
29056
+ school = new ObjectId45(school);
29057
+ } catch (error) {
29058
+ throw new BadRequestError69("Invalid school ID.");
29059
+ }
29060
+ const cacheKey = makeCacheKey22(namespace_collection, {
29061
+ school,
29062
+ type: "supplier-as-options"
29063
+ });
29064
+ const cachedData = await getCache(cacheKey);
29065
+ if (cachedData) {
29066
+ return cachedData;
29067
+ }
29068
+ try {
29069
+ const suppliers = await collection.aggregate([
29070
+ {
29071
+ $match: { school }
29072
+ },
29073
+ {
29074
+ $group: {
29075
+ _id: "$supplier",
29076
+ value: { $first: "$supplier" },
29077
+ title: {
29078
+ $first: "$supplier"
29079
+ }
29080
+ }
29081
+ },
29082
+ {
29083
+ $project: {
29084
+ _id: 0,
29085
+ title: 1,
29086
+ value: 1
29087
+ }
29088
+ },
29089
+ { $sort: { title: 1 } }
29090
+ ]).toArray();
29091
+ setCache(cacheKey, suppliers).then(() => {
29092
+ logger34.log({
29093
+ level: "info",
29094
+ message: `Cache set for getSuppliersBySchool: ${cacheKey}`
29095
+ });
29096
+ }).catch((err) => {
29097
+ logger34.log({
29098
+ level: "error",
29099
+ message: `Failed to set cache for getSuppliersBySchool: ${err.message}`
29100
+ });
29101
+ });
29102
+ return suppliers;
29103
+ } catch (error) {
29104
+ if (error instanceof BadRequestError69) {
29105
+ throw error;
29106
+ }
29107
+ throw new BadRequestError69("Failed to retrieve asset suppliers.");
29108
+ }
29109
+ }
29110
+ return {
29111
+ createIndex,
29112
+ add,
29113
+ getById,
29114
+ getAll,
29115
+ getSuppliers
29116
+ };
29117
+ }
29118
+
29119
+ // src/controllers/stock-card.controller.ts
29120
+ import { BadRequestError as BadRequestError71 } from "@eeplatform/nodejs-utils";
29121
+ import Joi39 from "joi";
29122
+
29123
+ // src/services/stock-card.service.ts
29124
+ import {
29125
+ BadRequestError as BadRequestError70,
29126
+ NotFoundError as NotFoundError11,
29127
+ useAtlas as useAtlas37
29128
+ } from "@eeplatform/nodejs-utils";
29129
+ function useStockCardService() {
29130
+ const { add: _add, getById: _getById } = useStockCardRepository();
29131
+ const { getById: _getAssetById, updateById: updateAssetById } = useAssetRepo();
29132
+ async function add(data) {
29133
+ const session = useAtlas37.getClient()?.startSession();
29134
+ if (!session) {
29135
+ throw new BadRequestError70("Unable to start database session.");
29136
+ }
29137
+ session.startTransaction();
29138
+ try {
29139
+ const asset = await _getAssetById(data.item);
29140
+ if (!asset) {
29141
+ throw new NotFoundError11("Asset not found.");
29142
+ }
29143
+ data.balance = (asset.qty ?? 0) + data.qty;
29144
+ await _add(data, session);
29145
+ await updateAssetById(data.item, { qty: data.balance }, session);
29146
+ await session.commitTransaction();
29147
+ return "Successfully added stock card.";
29148
+ } catch (error) {
29149
+ await session.abortTransaction();
29150
+ throw new BadRequestError70("Failed to add stock card.");
29151
+ } finally {
29152
+ session.endSession();
29153
+ }
29154
+ }
29155
+ return {
29156
+ add
29157
+ };
29158
+ }
29159
+
29160
+ // src/controllers/stock-card.controller.ts
29161
+ function useStockCardController() {
29162
+ const {
29163
+ getAll: _getAll,
29164
+ getById: _getById,
29165
+ getSuppliers: _getSuppliers
29166
+ } = useStockCardRepository();
29167
+ const { add: _add } = useStockCardService();
29168
+ async function add(req, res, next) {
29169
+ const value = req.body;
29170
+ const { error } = schemaStockCard.validate(value);
29171
+ if (error) {
29172
+ next(new BadRequestError71(error.message));
29173
+ return;
29174
+ }
29175
+ try {
29176
+ const id = await _add(value);
29177
+ res.json({ message: "Successfully added asset item.", id });
29178
+ } catch (error2) {
29179
+ next(error2);
29180
+ }
29181
+ }
29182
+ async function getAll(req, res, next) {
29183
+ const query = req.query;
29184
+ const validation = Joi39.object({
29185
+ page: Joi39.number().min(1).optional().allow("", null),
29186
+ limit: Joi39.number().min(1).optional().allow("", null),
29187
+ school: Joi39.string().hex().optional().allow("", null),
29188
+ id: Joi39.string().hex().required()
29189
+ });
29190
+ const { error } = validation.validate(query);
29191
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
29192
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
29193
+ const school = req.query.school ?? "";
29194
+ const id = req.query.id ?? "supply";
29195
+ const isPageNumber = isFinite(page);
29196
+ if (!isPageNumber) {
29197
+ next(new BadRequestError71("Invalid page number."));
29198
+ return;
29199
+ }
29200
+ const isLimitNumber = isFinite(limit);
29201
+ if (!isLimitNumber) {
29202
+ next(new BadRequestError71("Invalid limit number."));
29203
+ return;
29204
+ }
29205
+ if (error) {
29206
+ next(new BadRequestError71(error.message));
29207
+ return;
29208
+ }
29209
+ try {
29210
+ const regions = await _getAll({
29211
+ page,
29212
+ limit,
29213
+ id,
29214
+ school
29215
+ });
29216
+ res.json(regions);
29217
+ return;
29218
+ } catch (error2) {
29219
+ next(error2);
29220
+ }
29221
+ }
29222
+ async function getById(req, res, next) {
29223
+ const id = req.params.id;
29224
+ const validation = Joi39.string().hex().required();
29225
+ const { error } = validation.validate(id);
29226
+ if (error) {
29227
+ next(new BadRequestError71(error.message));
29228
+ return;
29229
+ }
29230
+ try {
29231
+ const data = await _getById(id);
29232
+ res.json(data);
29233
+ } catch (error2) {
29234
+ next(error2);
29235
+ }
29236
+ }
29237
+ async function getSuppliers(req, res, next) {
29238
+ const school = req.params.school;
29239
+ const validation = Joi39.string().hex().required();
29240
+ const { error } = validation.validate(school);
29241
+ if (error) {
29242
+ next(new BadRequestError71(error.message));
29243
+ return;
29244
+ }
29245
+ try {
29246
+ const data = await _getSuppliers(school);
29247
+ res.json(data);
29248
+ } catch (error2) {
29249
+ next(error2);
29250
+ }
29251
+ }
29252
+ return {
29253
+ add,
29254
+ getAll,
29255
+ getById,
29256
+ getSuppliers
28571
29257
  };
28572
29258
  }
28573
29259
  export {
@@ -28588,12 +29274,12 @@ export {
28588
29274
  MAILER_TRANSPORT_PORT,
28589
29275
  MAILER_TRANSPORT_SECURE,
28590
29276
  MAddress,
29277
+ MAsset,
28591
29278
  MBuilding,
28592
29279
  MBuildingUnit,
28593
29280
  MDivision,
28594
29281
  MEntity,
28595
29282
  MFile,
28596
- MInventory,
28597
29283
  MMember,
28598
29284
  MONGO_DB,
28599
29285
  MONGO_URI,
@@ -28604,6 +29290,7 @@ export {
28604
29290
  MRegion,
28605
29291
  MRole,
28606
29292
  MSchool,
29293
+ MStockCard,
28607
29294
  MSubscription,
28608
29295
  MToken,
28609
29296
  MUser,
@@ -28631,16 +29318,19 @@ export {
28631
29318
  addressSchema,
28632
29319
  isDev,
28633
29320
  schema,
29321
+ schemaAsset,
29322
+ schemaAssetUpdateOption,
28634
29323
  schemaBuilding,
28635
29324
  schemaBuildingUnit,
28636
29325
  schemaDivision,
28637
- schemaInventory,
28638
- schemaInventoryUpdateOption,
28639
29326
  schemaRegion,
28640
29327
  schemaSchool,
29328
+ schemaStockCard,
28641
29329
  schemaUpdateOptions,
28642
29330
  useAddressController,
28643
29331
  useAddressRepo,
29332
+ useAssetController,
29333
+ useAssetRepo,
28644
29334
  useAuthController,
28645
29335
  useAuthService,
28646
29336
  useBuildingController,
@@ -28657,8 +29347,6 @@ export {
28657
29347
  useFileController,
28658
29348
  useFileRepo,
28659
29349
  useFileService,
28660
- useInventoryController,
28661
- useInventoryRepo,
28662
29350
  useInvoiceController,
28663
29351
  useInvoiceModel,
28664
29352
  useInvoiceRepo,
@@ -28690,6 +29378,8 @@ export {
28690
29378
  useSchoolController,
28691
29379
  useSchoolRepo,
28692
29380
  useSchoolService,
29381
+ useStockCardController,
29382
+ useStockCardRepository,
28693
29383
  useSubscriptionController,
28694
29384
  useSubscriptionRepo,
28695
29385
  useSubscriptionService,