Skip to content

Commit c3d4276

Browse files
authored
Merge pull request #118 from bakaphp/feat/add-app-functions
Feat/add app functions
2 parents d482527 + f7a6f8c commit c3d4276

File tree

7 files changed

+53
-84
lines changed

7 files changed

+53
-84
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22

3-
"version": "0.0.62",
3+
"version": "0.0.63",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

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/mutations/app.mutation.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ export const APP_CREATE_USER = gql`
4444
}
4545
}
4646
`;
47+
48+
export const APP_ACTIVE_USER = gql`
49+
mutation($user_id: ID!) {
50+
appActivateUser(user_id: $user_id)
51+
}
52+
`;
53+
54+
export const APP_DEACTIVE_USER = gql`
55+
mutation appDeActiveUser($user_id: ID!) {
56+
appDeActiveUser(user_id: $user_id)
57+
}
58+
`;

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/app.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,11 @@ export interface AppCreateUserParams {
100100
export interface CreatedAppCreateUser {
101101
appCreateUser: AppUserInterface;
102102
}
103+
104+
export interface AppActivateUser {
105+
appActivateUser: boolean;
106+
}
107+
108+
export interface AppDeactiveUser {
109+
appDeActiveUser: boolean;
110+
}

src/types/users.ts

Lines changed: 2 additions & 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: {
@@ -124,6 +125,7 @@ export interface UpdateUserParams {
124125
displayname?: string;
125126
phone_number: string;
126127
cell_phone_number: string;
128+
role_id?: number | string;
127129
custom_fields: {
128130
name: string;
129131
data: any;

0 commit comments

Comments
 (0)