Skip to content

Commit 576bb23

Browse files
committed
feat(app): add user activation and deactivation functionality
1 parent 0982b84 commit 576bb23

File tree

4 files changed

+31
-83
lines changed

4 files changed

+31
-83
lines changed

src/modules/app/index.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { AppUserInterface, AppUpdatePasswordInterface, WhereCondition, AllAppUsersInterface, OrderBy, AppCreateUserParams, CreatedAppCreateUser } from '../../types';
2-
import { APP_CREATE_USER, USER_UPDATE_PASSWORD_MUTATION } from '../../mutations';
3-
import { APP_USERS_QUERY, GET_ALL_APP_USERS } from '../../queries';
1+
import type { AppUserInterface, AppUpdatePasswordInterface, WhereCondition, AllAppUsersInterface, OrderBy, AppCreateUserParams, CreatedAppCreateUser, AppActivateUser, AppDeactiveUser, } from '../../types';
2+
import { APP_ACTIVE_USER, APP_CREATE_USER, APP_DEACTIVE_USER, USER_UPDATE_PASSWORD_MUTATION } from '../../mutations';
3+
import { GET_APP_USERS } from '../../queries';
44
import type { ClientType } from '../../index';
55

66
class Users {
@@ -36,7 +36,7 @@ class Users {
3636
* */
3737
public async getUserByEmail(email: string): Promise<AppUserInterface> {
3838
const response = await this.client.query({
39-
query: APP_USERS_QUERY,
39+
query: GET_APP_USERS,
4040
variables: {
4141
first: 1,
4242
where: {
@@ -50,7 +50,7 @@ class Users {
5050
return response.data.appUsers.data[0];
5151
}
5252

53-
public async getAllAppUsers(
53+
public async getAppUsers(
5454
options: {
5555
first?: number;
5656
page?: number;
@@ -62,7 +62,7 @@ class Users {
6262
const { first, page, whereCondition, orderByCondition, search } = options;
6363

6464
const response = await this.client.query({
65-
query: GET_ALL_APP_USERS,
65+
query: GET_APP_USERS,
6666
variables: {
6767
first,
6868
page,
@@ -76,13 +76,6 @@ class Users {
7676
return response.data;
7777
}
7878

79-
}
80-
81-
82-
class Admin {
83-
constructor(protected client: ClientType) { }
84-
85-
8679
public async appCreateUser(data: AppCreateUserParams): Promise<CreatedAppCreateUser> {
8780
const response = await this.client.mutate({
8881
mutation: APP_CREATE_USER,
@@ -92,16 +85,32 @@ class Admin {
9285
return response.data
9386
}
9487

88+
public async appActivateUser(user_id: number | string): Promise<AppActivateUser> {
89+
const response = await this.client.mutate({
90+
mutation: APP_ACTIVE_USER,
91+
variables: { user_id: user_id },
92+
});
93+
94+
return response.data
95+
}
96+
97+
public async appDeactivateUser(user_id: number | string): Promise<AppDeactiveUser> {
98+
const response = await this.client.mutate({
99+
mutation: APP_DEACTIVE_USER,
100+
variables: { user_id: user_id },
101+
});
102+
103+
return response.data
104+
}
95105

96106
}
97107

108+
98109
export class App {
99110
public users: Users;
100-
public admin: Admin;
101111

102112
constructor(protected client: ClientType) {
103113
this.users = new Users(this.client);
104-
this.admin = new Admin(this.client);
105114

106115
}
107116
}

src/queries/app.query.ts

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,7 @@
11
import { gql } from '@apollo/client/core';
22

3-
export const APP_USERS_QUERY = gql`
4-
query filterUser($first: Int, $where: QueryAppUsersWhereWhereConditions) {
5-
appUsers(first: $first, where: $where) {
6-
data {
7-
id
8-
uuid
9-
email
10-
displayname
11-
lastname
12-
firstname
13-
sex
14-
description
15-
user_active
16-
address {
17-
address_1
18-
address_2
19-
city {
20-
id
21-
name
22-
latitude
23-
longitude
24-
states_id
25-
countries_id
26-
}
27-
country {
28-
id
29-
name
30-
code
31-
flag
32-
}
33-
zip_code
34-
state {
35-
id
36-
code
37-
name
38-
}
39-
}
40-
contact {
41-
phone_number
42-
cell_phone_number
43-
}
44-
companies {
45-
id
46-
uuid
47-
name
48-
}
49-
branches {
50-
id
51-
name
52-
companies_id
53-
}
54-
created_at
55-
updated_at
56-
}
57-
paginatorInfo {
58-
currentPage
59-
lastPage
60-
}
61-
}
62-
}
63-
`;
64-
65-
export const GET_ALL_APP_USERS = gql`
66-
query getAllAppUsers(
3+
export const GET_APP_USERS = gql`
4+
query getAppUsers(
675
$first: Int
686
$page: Int
697
$whereCondition: QueryAppUsersWhereWhereConditions
@@ -88,6 +26,7 @@ export const GET_ALL_APP_USERS = gql`
8826
description
8927
user_active
9028
roles
29+
is_active
9130
address {
9231
address_1
9332
address_2

src/queries/inventory.query.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ export const GET_PRODUCT_TYPES = gql`
151151
`;
152152

153153
export const GET_STATUS = gql`
154-
query getStatus($whereCondition: QueryGetStatusWhereWhereConditions) {
155-
getStatus(where: $whereCondition) {
154+
query getStatus($whereCondition: [QueryGetStatusWhereWhereConditions!]) {
155+
getStatus(where: { AND: $whereCondition }) {
156156
data {
157157
name
158158
id
@@ -297,7 +297,6 @@ export const GET_VARIANTS = gql`
297297
name
298298
value
299299
}
300-
301300
product {
302301
id
303302
slug
@@ -335,7 +334,7 @@ export const GET_VARIANTS = gql`
335334
export const GET_VARIANTS_BY_STATUS = gql`
336335
query getVariantsByStatus(
337336
$warehouse_id: ID!
338-
$status_id: [ID]!
337+
$status_id: [ID]!
339338
$first: Int
340339
$page: Int
341340
$whereCondition: QueryVariantsByStatusWhereWhereConditions

src/types/users.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export interface UserData {
106106
cell_phone_number: string;
107107
};
108108
roles: string[];
109+
is_active: boolean;
109110
abilities: string[];
110111
custom_fields: {
111112
data: {

0 commit comments

Comments
 (0)