Skip to content

Commit

Permalink
Fix issues wit hmigration and queires (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
wil92 committed May 5, 2023
1 parent 89bb32b commit 0c7a977
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/db/migrations/1.0.0-initial_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ module.exports = {
actions: ['topPopularUsers', 'topActiveUsers', 'find', 'findOne', 'users', 'update'],
type: 'plugin'
},
{
roles: [publicRole, authRole, staffRole, adminRole],
controller: 'users-permissions.role',
actions: ['find', 'findOne'],
type: 'plugin'
},
{
roles: [publicRole, authRole, staffRole, adminRole],
controller: 'users-permissions.auth',
Expand Down
33 changes: 20 additions & 13 deletions src/extensions/users-permissions/config/schema.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,18 @@ module.exports = (strapi) => {
}
});

const TopUsers = nexus.objectType({
name: 'TopUsers',
const UsersPermissionsUserEntityRes = nexus.objectType({
name: 'UsersPermissionsUserEntityRes',
definition(t) {
t.list.field('users', {type: 'UsersPermissionsUserEntity'});
t.list.field('values', {type: 'Int'});
t.field('data', {type: 'UsersPermissionsUserEntity'});
}
});

const myData = nexus.extendType({
type: 'Query',
const TopUsers = nexus.objectType({
name: 'TopUsers',
definition(t) {
t.field('myData', {
type: nexus.nonNull('UsersPermissionsMYData'),
resolve(parent, args, context) {
return strapi.service('plugin::users-permissions.extra').myData(context);
}
});
t.list.field('users', {type: 'UsersPermissionsUserEntityRes'});
t.list.field('values', {type: 'Int'});
}
});

Expand Down Expand Up @@ -80,6 +75,18 @@ module.exports = (strapi) => {
}
});

const myData = nexus.extendType({
type: 'Query',
definition(t) {
t.field('myData', {
type: nexus.nonNull('UsersPermissionsMYData'),
resolve(parent, args, context) {
return strapi.service('plugin::users-permissions.extra').myData(context);
}
});
}
});

const users = nexus.extendType({
type: 'Query',
definition(t) {
Expand Down Expand Up @@ -111,7 +118,7 @@ module.exports = (strapi) => {
});

return {
types: [UsersPermissionsUser2, UsersPermissionsMYData, TopUsers, myData, topActiveUsers, topPopularUsers,
types: [UsersPermissionsUser2, UsersPermissionsMYData, UsersPermissionsUserEntityRes, TopUsers, myData, topActiveUsers, topPopularUsers,
users, loginWithProvider]
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/users-permissions/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = (services) => {
}, new Map());
users = users.sort((a, b) => ma.get(b.id) - ma.get(a.id));
const values = usersQuery.map(v => +v.counter);
return {users, values};
return {users: users.map(data => ({data})), values};
},

async users(args) {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/user/get-active-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const expect = chai.expect;
const QUERY_GET_ACTIVE_USERS = {
operationName: null,
// language=GraphQL
query: 'query {\n topActiveUsers {\n users {\n id\n attributes {\n username\n email\n provider\n confirmed\n blocked\n role {\n data {\n attributes {\n type\n name\n }\n }\n }\n avatar {\n data {\n attributes {\n url\n }\n }\n }\n avatarUrl\n name\n page\n createdAt\n updatedAt\n }\n }\n values\n }\n}\n'
query: 'query {\n topActiveUsers {\n users {\n data {\n id\n attributes {\n username\n email\n provider\n confirmed\n blocked\n role {\n data {\n attributes {\n type\n name\n }\n }\n }\n avatar {\n data {\n attributes {\n url\n }\n }\n }\n avatarUrl\n name\n page\n createdAt\n updatedAt\n }\n }\n }\n values\n }\n}\n'
};
const MAX_NUMBER = 10;

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Get more active users INTEGRATION', () => {
expect(topValues.length).to.be.equal(strapi.config.custom.maxNumberOfTopUsers);

for (let i = 0; i < strapi.config.custom.maxNumberOfTopUsers; i++) {
expect(+topUsers[i].id).to.be.equal(users[MAX_NUMBER - i - 2].id);
expect(+topUsers[i].data.id).to.be.equal(users[MAX_NUMBER - i - 2].id);
}

for (let i = 0; i < strapi.config.custom.maxNumberOfTopUsers; i++) {
Expand All @@ -77,7 +77,7 @@ describe('Get more active users INTEGRATION', () => {
expect(topValues.length).to.be.equal(strapi.config.custom.maxNumberOfTopUsers);

for (let i = 0; i < strapi.config.custom.maxNumberOfTopUsers; i++) {
expect(+topUsers[i].id).to.be.equal(+users[MAX_NUMBER - i - 2].id);
expect(+topUsers[i].data.id).to.be.equal(+users[MAX_NUMBER - i - 2].id);
}

for (let i = 0; i < strapi.config.custom.maxNumberOfTopUsers; i++) {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/user/get-popular-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const expect = chai.expect;
const QUERY_GET_POPULAR_USERS = {
operationName: null,
// language=GraphQL
query: 'query {\n topPopularUsers {\n users {\n id\n attributes {\n username\n email\n provider\n confirmed\n blocked\n role {\n data {\n attributes {\n type\n name\n }\n }\n }\n avatar {\n data {\n attributes {\n url\n }\n }\n }\n avatarUrl\n name\n page\n createdAt\n updatedAt\n }\n }\n values\n }\n}\n'
query: 'query {\n topPopularUsers {\n users {\n data {\n id\n attributes {\n username\n email\n provider\n confirmed\n blocked\n role {\n data {\n attributes {\n type\n name\n }\n }\n }\n avatar {\n data {\n attributes {\n url\n }\n }\n }\n avatarUrl\n name\n page\n createdAt\n updatedAt\n }\n }\n }\n values\n }\n}\n'
};
const MAX_NUMBER = 10;

Expand Down Expand Up @@ -53,7 +53,7 @@ describe('Get popular users INTEGRATION', () => {
expect(topValues.length).to.be.equal(strapi.config.custom.maxNumberOfTopUsers);

for (let i = 0; i < strapi.config.custom.maxNumberOfTopUsers; i++) {
expect(+topUsers[i].id).to.be.equal(+users[MAX_NUMBER - i - 1].id);
expect(+topUsers[i].data.id).to.be.equal(+users[MAX_NUMBER - i - 1].id);
}
});

Expand All @@ -72,7 +72,7 @@ describe('Get popular users INTEGRATION', () => {
expect(topValues.length).to.be.equal(strapi.config.custom.maxNumberOfTopUsers);

for (let i = 0; i < strapi.config.custom.maxNumberOfTopUsers; i++) {
expect(+topUsers[i].id).to.be.equal(+users[MAX_NUMBER - i - 1].id);
expect(+topUsers[i].data.id).to.be.equal(+users[MAX_NUMBER - i - 1].id);
}
});
});

0 comments on commit 0c7a977

Please sign in to comment.