@eeplatform/basic-edu 1.3.5 → 1.3.7

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
@@ -4518,6 +4518,7 @@ function useSchoolRepo() {
4518
4518
  { key: { name: 1 } },
4519
4519
  { key: { createdAt: 1 } },
4520
4520
  { key: { name: "text" } },
4521
+ { key: { cityMunicipalityPSGC: 1 }, unique: true, name: "unique_psgc" },
4521
4522
  { key: { id: 1, status: 1 }, unique: true, name: "unique_school_id" }
4522
4523
  ]);
4523
4524
  } catch (error) {
@@ -4574,20 +4575,25 @@ function useSchoolRepo() {
4574
4575
  page = 1,
4575
4576
  limit = 10,
4576
4577
  sort = {},
4577
- status = "active"
4578
+ status = "active",
4579
+ prefix = ""
4578
4580
  } = {}) {
4579
4581
  page = page > 0 ? page - 1 : 0;
4580
4582
  const query = {
4581
4583
  deletedAt: { $in: ["", null] },
4582
4584
  status
4583
4585
  };
4584
- sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
4586
+ sort = Object.keys(sort).length > 0 ? sort : {};
4585
4587
  const cacheKeyOptions = {
4586
4588
  status,
4587
4589
  page,
4588
4590
  limit,
4589
4591
  sort: JSON.stringify(sort)
4590
4592
  };
4593
+ if (prefix) {
4594
+ query.cityMunicipalityPSGC = { $regex: `^${prefix}` };
4595
+ cacheKeyOptions.prefix = prefix;
4596
+ }
4591
4597
  if (search) {
4592
4598
  query.$text = { $search: search };
4593
4599
  cacheKeyOptions.search = search;
@@ -4606,12 +4612,12 @@ function useSchoolRepo() {
4606
4612
  });
4607
4613
  return cached;
4608
4614
  }
4609
- const items = await collection.aggregate([
4610
- { $match: query },
4611
- { $sort: sort },
4612
- { $skip: page * limit },
4613
- { $limit: limit }
4614
- ]).toArray();
4615
+ const pipeline = [{ $match: query }];
4616
+ if (Object.keys(sort).length > 0) {
4617
+ pipeline.push({ $sort: sort });
4618
+ }
4619
+ pipeline.push({ $skip: page * limit }, { $limit: limit });
4620
+ const items = await collection.aggregate(pipeline).toArray();
4615
4621
  const length = await collection.countDocuments(query);
4616
4622
  const data = paginate6(items, page, limit, length);
4617
4623
  setCache(cacheKey, data, 600).then(() => {
@@ -33408,7 +33414,8 @@ function useSchoolController() {
33408
33414
  status: Joi11.string().optional().allow(null, ""),
33409
33415
  org: Joi11.string().hex().optional().allow(null, ""),
33410
33416
  app: Joi11.string().optional().allow(null, ""),
33411
- search: Joi11.string().optional().allow(null, "")
33417
+ search: Joi11.string().optional().allow(null, ""),
33418
+ psgc: Joi11.string().optional().allow(null, "")
33412
33419
  });
33413
33420
  const { error } = validation.validate(req.query);
33414
33421
  if (error) {
@@ -33428,13 +33435,15 @@ function useSchoolController() {
33428
33435
  }
33429
33436
  const status = req.query.status ?? "active";
33430
33437
  const search = req.query.search ?? "";
33438
+ const psgc = req.query.psgc ?? "";
33431
33439
  try {
33432
33440
  const schools = await _getAll({
33433
33441
  page,
33434
33442
  limit,
33435
33443
  sort: sortObj,
33436
33444
  status,
33437
- search
33445
+ search,
33446
+ prefix: psgc
33438
33447
  });
33439
33448
  res.status(200).json(schools);
33440
33449
  return;