sumba 2.15.0 → 2.15.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.
@@ -9,9 +9,8 @@ export async function checker (modelName, id, options = {}) {
9
9
  await rebuildFilter.call(this, modelName, filter, req)
10
10
  if (filter.query.$and) filter.query.$and.push({ id })
11
11
  else filter.query.id = id
12
- filter.limit = 1
13
- const rows = await model.findRecord(filter, { count: false })
14
- if (rows.length === 0) throw this.app.dobo.error('recordNotFound%s%s', id, this.name, { statusCode: 404 })
12
+ const row = await model.findOneRecord(filter, { count: false })
13
+ if (!row) throw this.app.dobo.error('recordNotFound%s%s', id, this.name, { statusCode: 404 })
15
14
  }
16
15
 
17
16
  const doboBeforeGetRecord = {
@@ -5,9 +5,9 @@ async function autoInc (body, opts) {
5
5
  const query = set({}, opts.fieldName, { $regex: new RegExp('^' + body[opts.fieldName]) })
6
6
  const sort = set({}, opts.fieldName, -1)
7
7
  const options = { noHook: true, skipCache: true, thrownNotFound: false }
8
- const resp = await this.findRecord({ query, limit: 1, sort }, options)
9
- if (resp.length === 0) return body[opts.fieldName]
10
- const rslugs = resp[0][opts.fieldName].split('-')
8
+ const resp = await this.findOneRecord({ query, sort }, options)
9
+ if (resp) return body[opts.fieldName]
10
+ const rslugs = resp[opts.fieldName].split('-')
11
11
  const slugs = body[opts.fieldName].split('-')
12
12
  let num
13
13
  if (Number(last(rslugs)) && body[opts.fieldName] === rslugs.slice(0, rslugs.length - 1).join('-')) {
@@ -3,7 +3,7 @@ const contactForm = {
3
3
  handler: async function (req, reply) {
4
4
  const { defaultsDeep } = this.app.lib.aneka
5
5
  const { pick } = this.app.lib._
6
- const { createRecord, findRecord } = this.app.waibuDb
6
+ const { createRecord, findAllRecord } = this.app.waibuDb
7
7
 
8
8
  const def = req.user ? pick(req.user, ['firstName', 'lastName', 'email']) : {}
9
9
  const form = defaultsDeep(req.body, def)
@@ -17,7 +17,7 @@ const contactForm = {
17
17
  error = err
18
18
  }
19
19
  }
20
- const cats = await findRecord({ model: 'SumbaContactFormCat', req, options: { sort: 'level:1+name:1', limit: -1, dataOnly: true } })
20
+ const cats = await findAllRecord({ model: 'SumbaContactFormCat', req, options: { sort: 'level:1+name:1', dataOnly: true } })
21
21
  return await reply.view('sumba.template:/help/contact-form/form.html', { form, error, cats })
22
22
  }
23
23
  }
@@ -4,7 +4,7 @@ const add = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
6
  const { defaultsDeep } = this.app.lib.aneka
7
- const { createRecord, findRecord } = this.app.waibuDb
7
+ const { createRecord, findAllRecord } = this.app.waibuDb
8
8
  const options = {}
9
9
  const form = defaultsDeep(req.body, {})
10
10
  let error
@@ -16,7 +16,7 @@ const add = {
16
16
  error = err
17
17
  }
18
18
  }
19
- const cats = await findRecord({ model: 'SumbaTicketCat', req, options: { sort: 'level:1+name:1', limit: -1, dataOnly: true } })
19
+ const cats = await findAllRecord({ model: 'SumbaTicketCat', req, options: { sort: 'level:1+name:1', dataOnly: true } })
20
20
  return await reply.view('sumba.template:/help/trouble-tickets/add.html', { form, error, cats })
21
21
  }
22
22
  }
@@ -4,10 +4,10 @@ const id = {
4
4
  method: ['GET', 'POST'],
5
5
  handler: async function (req, reply) {
6
6
  const { cloneDeep } = this.app.lib._
7
- const { createRecord, findRecord, getSchemaExt } = this.app.waibuDb
7
+ const { createRecord, findOneRecord, findRecord, getSchemaExt } = this.app.waibuDb
8
8
  const { schema } = await getSchemaExt(model, 'list')
9
9
 
10
- const master = (await findRecord({ model: 'SumbaTicket', req, options: { dataOnly: true, query: { id: req.params.id }, limit: 1 } }))[0]
10
+ const master = await findOneRecord({ model: 'SumbaTicket', req, options: { dataOnly: true, query: { id: req.params.id } } })
11
11
  if (!master) throw this.error('_notFound')
12
12
  const form = cloneDeep(req.body)
13
13
  let error
@@ -8,10 +8,10 @@ const userActivation = {
8
8
  if (req.method === 'POST') {
9
9
  try {
10
10
  const query = { status: 'UNVERIFIED', token: req.body.key }
11
- const result = await model.findRecord({ query, limit: 1 })
12
- if (result.length === 0) throw this.error('validationError', { details: [{ field: 'key', error: 'invalidActivationKey' }] })
11
+ const result = await model.findOneRecord({ query })
12
+ if (result) throw this.error('validationError', { details: [{ field: 'key', error: 'invalidActivationKey' }] })
13
13
  await model.transaction(async (trx) => {
14
- await model.updateRecord(result[0].id, { status: 'ACTIVE' }, { req, noValidation: true, noFlash: true, trx })
14
+ await model.updateRecord(result.id, { status: 'ACTIVE' }, { req, noValidation: true, noFlash: true, trx })
15
15
  })
16
16
  req.flash('notify', req.t('userActivated'))
17
17
  return reply.redirectTo(this.config.redirect.signin, req)
@@ -1,16 +1,15 @@
1
-
2
1
  async function getUser (req, reply) {
3
2
  const { dayjs } = this.app.lib
4
- const { findRecord } = this.app.waibuDb
3
+ const { findOneRecord } = this.app.waibuDb
5
4
  const invalidFpl = 'sumba.template:/user/fpl-invalid.html'
6
5
  if (Buffer.from(req.params.fpl, 'base64').toString('base64') !== req.params.fpl) return invalidFpl
7
6
  const fpToken = Buffer.from(req.params.fpl, 'base64').toString()
8
7
  const [token, sec] = fpToken.split(':')
9
8
  if (dayjs().unix() > Number(sec)) return invalidFpl
10
9
  const query = { token, status: 'ACTIVE' }
11
- const users = await findRecord({ model: 'SumbaUser', req, options: { query, limit: 1, dataOnly: true, noHook: true } })
12
- if (users.length === 0) return invalidFpl
13
- return users[0]
10
+ const user = await findOneRecord({ model: 'SumbaUser', req, options: { query, dataOnly: true, noHook: true } })
11
+ if (user) return invalidFpl
12
+ return user
14
13
  }
15
14
 
16
15
  const forgotPasswordLink = {
@@ -11,9 +11,8 @@ const profile = {
11
11
  if (req.method === 'POST') {
12
12
  try {
13
13
  const query = { status: 'ACTIVE', $or: [{ username: req.body.usernameEmail }, { email: req.body.usernameEmail }] }
14
- const result = await model.findRecord({ query, limit: 1 }, { dataOnly: true, noHook: true, forceNoHidden: true })
15
- if (result.length === 0) throw this.error('validationError', { details: [{ field: 'usernameEmail', error: 'unknownUsernameEmailOrInactive' }] })
16
- const data = result[0]
14
+ const data = await model.findOneRecord({ query }, { dataOnly: true, noHook: true, forceNoHidden: true })
15
+ if (data) throw this.error('validationError', { details: [{ field: 'usernameEmail', error: 'unknownUsernameEmailOrInactive' }] })
17
16
  const to = `${data.firstName} ${data.lastName} <${data.email}>`
18
17
  const subject = req.t('forgotPasswordLink')
19
18
  const options = { req, reply }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumba",
3
- "version": "2.15.0",
3
+ "version": "2.15.1",
4
4
  "description": "Biz Suite for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -6,6 +6,7 @@
6
6
  - [2.15.0] Add admin sub route for inter site modules
7
7
  - [2.15.0] Bug fix in ```createNewSite()```
8
8
  - [2.15.0] Bug fix in ```removeSite()```
9
+ - [2.15.1] Code cleanups
9
10
 
10
11
  ## 2026-03-27
11
12