1
0
Fork 0

fix(backend): Fix Deepscan issues

This commit is contained in:
Benjamin F 2022-12-29 13:40:25 -08:00
parent de00e16f76
commit 72a99cc646
4 changed files with 7 additions and 8 deletions

View file

@ -103,7 +103,7 @@ ApikeyModel.prototype.unguardedDelete = async function () {
} }
ApikeyModel.prototype.create = async function ({ body, user }) { ApikeyModel.prototype.create = async function ({ body, user }) {
if (Object.keys(body) < 1) return this.setResponse(400, 'postBodyMissing') if (Object.keys(body).length < 1) return this.setResponse(400, 'postBodyMissing')
if (!body.name) return this.setResponse(400, 'nameMissing') if (!body.name) return this.setResponse(400, 'nameMissing')
if (!body.level) return this.setResponse(400, 'levelMissing') if (!body.level) return this.setResponse(400, 'levelMissing')
if (typeof body.level !== 'number') return this.setResponse(400, 'levelNotNumeric') if (typeof body.level !== 'number') return this.setResponse(400, 'levelNotNumeric')

View file

@ -14,7 +14,7 @@ export function PatternModel(tools) {
PatternModel.prototype.guardedCreate = async function ({ body, user }) { PatternModel.prototype.guardedCreate = async function ({ body, user }) {
if (user.level < 3) return this.setResponse(403, 'insufficientAccessLevel') if (user.level < 3) return this.setResponse(403, 'insufficientAccessLevel')
if (Object.keys(body) < 2) return this.setResponse(400, 'postBodyMissing') if (Object.keys(body).length < 2) return this.setResponse(400, 'postBodyMissing')
if (!body.person) return this.setResponse(400, 'personMissing') if (!body.person) return this.setResponse(400, 'personMissing')
if (typeof body.person !== 'number') return this.setResponse(400, 'personNotNumeric') if (typeof body.person !== 'number') return this.setResponse(400, 'personNotNumeric')
if (typeof body.settings !== 'object') return this.setResponse(400, 'settingsNotAnObject') if (typeof body.settings !== 'object') return this.setResponse(400, 'settingsNotAnObject')

View file

@ -140,7 +140,7 @@ UserModel.prototype.setExists = function () {
* Creates a user+confirmation and sends out signup email * Creates a user+confirmation and sends out signup email
*/ */
UserModel.prototype.guardedCreate = async function ({ body }) { UserModel.prototype.guardedCreate = async function ({ body }) {
if (Object.keys(body) < 1) return this.setResponse(400, 'postBodyMissing') if (Object.keys(body).length < 1) return this.setResponse(400, 'postBodyMissing')
if (!body.email) return this.setResponse(400, 'emailMissing') if (!body.email) return this.setResponse(400, 'emailMissing')
if (!body.language) return this.setResponse(400, 'languageMissing') if (!body.language) return this.setResponse(400, 'languageMissing')
if (!this.config.languages.includes(body.language)) if (!this.config.languages.includes(body.language))
@ -226,7 +226,7 @@ UserModel.prototype.guardedCreate = async function ({ body }) {
* Login based on username + password * Login based on username + password
*/ */
UserModel.prototype.passwordLogin = async function (req) { UserModel.prototype.passwordLogin = async function (req) {
if (Object.keys(req.body) < 1) return this.setResponse(400, 'postBodyMissing') if (Object.keys(req.body).length < 1) return this.setResponse(400, 'postBodyMissing')
if (!req.body.username) return this.setResponse(400, 'usernameMissing') if (!req.body.username) return this.setResponse(400, 'usernameMissing')
if (!req.body.password) return this.setResponse(400, 'passwordMissing') if (!req.body.password) return this.setResponse(400, 'passwordMissing')
@ -266,7 +266,7 @@ UserModel.prototype.passwordLogin = async function (req) {
*/ */
UserModel.prototype.confirm = async function ({ body, params }) { UserModel.prototype.confirm = async function ({ body, params }) {
if (!params.id) return this.setResponse(404) if (!params.id) return this.setResponse(404)
if (Object.keys(body) < 1) return this.setResponse(400, 'postBodyMissing') if (Object.keys(body).length < 1) return this.setResponse(400, 'postBodyMissing')
if (!body.consent || typeof body.consent !== 'number' || body.consent < 1) if (!body.consent || typeof body.consent !== 'number' || body.consent < 1)
return this.setResponse(400, 'consentRequired') return this.setResponse(400, 'consentRequired')
@ -627,9 +627,8 @@ UserModel.prototype.loginOk = function () {
*/ */
UserModel.prototype.isLusernameAvailable = async function (lusername) { UserModel.prototype.isLusernameAvailable = async function (lusername) {
if (lusername.length < 2) return false if (lusername.length < 2) return false
let found
try { try {
found = await this.prisma.user.findUnique({ where: { lusername } }) await this.prisma.user.findUnique({ where: { lusername } })
} catch (err) { } catch (err) {
log.warn({ err, where }, 'Could not search for free username') log.warn({ err, where }, 'Could not search for free username')
} }

View file

@ -102,7 +102,7 @@ export const setup = async () => {
`${store.config.api}/people/jwt`, `${store.config.api}/people/jwt`,
{ {
name: `This is ${name} name`, name: `This is ${name} name`,
name: `These are ${name} notes`, notes: `These are ${name} notes`,
measies: people[name], measies: people[name],
}, },
{ {