Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issue 464 user services #465

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions src/services/me/me.class.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-unused-vars */
import User from '../../models/users.model'
import Profile from '../../models/profiles.model'

const debug = require('debug')('impresso/services:me')
const { BadRequest } = require('@feathersjs/errors')
const SequelizeService = require('../sequelize.service')
const Profile = require('../../models/profiles.model')
const { measureTime } = require('../../util/instruments')

class Service {
Expand All @@ -22,14 +22,23 @@ class Service {
}

async find(params) {
debug('[find] retrieve user from params:', params)
const user = await measureTime(() => this.sequelizeService.get(params.user.id, {}), 'me.find.db.user')
debug('[find] retrieve current user:', user.profile.uid)
debug('[find] retrieve user from params query:', params.query)
const client = this.app.get('sequelizeClient')
const user = await User.sequelize(client).findByPk(params.user.id, {
include: ['groups', 'profile', 'userBitmap'],
})
debug('[find] retrieve current user:', user.profile.uid, user.userBitmap?.bitmap, user.toJSON())

return User.getMe({
user,
const response = User.getMe({
user: {
...user.get(),
bitmap: user.userBitmap?.bitmap,
groups: user.groups?.map(d => d.toJSON()),
},
profile: user.profile,
})
debug('[find] response:', response)
return response
}

async update(id, data, params) {
Expand Down
15 changes: 11 additions & 4 deletions src/services/users/users.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import User from '../../models/users.model'
import Group from '../../models/groups.model'
import Profile from '../../models/profiles.model'
const { BadRequest, NotFound } = require('@feathersjs/errors')
const { BadRequest, NotFound, MethodNotAllowed } = require('@feathersjs/errors')
const shorthash = require('short-hash')
const nanoid = require('nanoid')
const { Op } = require('sequelize')
Expand All @@ -24,7 +24,11 @@ class Service {
}

async get(id, params) {
debug('[get] id:', id)
debug('[get] id:', id, 'provider:', params.provider, 'authenticated:', params.authenticated)
// if it is internal
if (!params.authenticated && params.provider) {
throw new MethodNotAllowed('Not allowed')
}
// if you're staff; otherwise get your own.
const userModel = await this.sequelizeKlass
.scope('isActive')
Expand Down Expand Up @@ -187,9 +191,12 @@ class Service {
}

async find(params) {
debug('find: ', params)
debug('[find] query:', params.query, 'provider:', params.provider)
let uid

// if it is internal
if (params.provider) {
throw new MethodNotAllowed('Not allowed')
}
if (params.sanitized.githubId) {
uid = `github-${params.sanitized.githubId}`
} else if (params.sanitized.email) {
Expand Down
Loading