@pinelab/vendure-plugin-customer-managed-groups 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +5 -1
- package/dist/api/admin-graphql.d.ts +1 -0
- package/dist/api/admin-graphql.js +19 -0
- package/dist/api/common-graphql.d.ts +1 -0
- package/dist/api/common-graphql.js +71 -0
- package/dist/{api-extensions.d.ts → api/customer-managed-groups.resolver.d.ts} +10 -3
- package/dist/api/customer-managed-groups.resolver.js +167 -0
- package/dist/{customer-managed-groups.service.d.ts → api/customer-managed-groups.service.d.ts} +9 -4
- package/dist/{customer-managed-groups.service.js → api/customer-managed-groups.service.js} +42 -13
- package/dist/api/generated/admin-graphql.d.ts +97 -0
- package/dist/{generated/graphql.d.ts → api/generated/shop-graphql.d.ts} +1 -1
- package/dist/api/generated/shop-graphql.js +2 -0
- package/dist/api/shop-graphql.d.ts +1 -0
- package/dist/api/shop-graphql.js +80 -0
- package/dist/customer-managed-groups.plugin.d.ts +0 -3
- package/dist/customer-managed-groups.plugin.js +11 -5
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/package.json +5 -3
- package/dist/api-extensions.js +0 -256
- /package/dist/{custom-fields.d.ts → api/custom-fields.d.ts} +0 -0
- /package/dist/{custom-fields.js → api/custom-fields.js} +0 -0
- /package/dist/{generated/graphql.js → api/generated/admin-graphql.js} +0 -0
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ This plugin allows customers to manage their own groups, called Customer Managed
|
|
|
13
13
|
Add the plugin to your config:
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { CustomerManagedGroupsPlugin } from 'vendure-plugin-customer-managed-group';
|
|
16
|
+
import { CustomerManagedGroupsPlugin } from '@pinelab/vendure-plugin-customer-managed-group';
|
|
17
17
|
plugins: [CustomerManagedGroupsPlugin];
|
|
18
18
|
```
|
|
19
19
|
|
|
@@ -121,3 +121,7 @@ extend type Query {
|
|
|
121
121
|
myCustomerManagedGroup: CustomerManagedGroup
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
|
+
|
|
125
|
+
### Contributions
|
|
126
|
+
|
|
127
|
+
Thanks [@mschipperheyn](https://github.com/mschipperheyn) for his contributions on this plugin.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const adminSchema: import("graphql").DocumentNode;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adminSchema = void 0;
|
|
4
|
+
const graphql_tag_1 = require("graphql-tag");
|
|
5
|
+
const common_graphql_1 = require("./common-graphql");
|
|
6
|
+
exports.adminSchema = (0, graphql_tag_1.gql) `
|
|
7
|
+
${common_graphql_1.commonSchema}
|
|
8
|
+
|
|
9
|
+
extend type Mutation {
|
|
10
|
+
"""
|
|
11
|
+
Create an empty group with the specified customer as Administrator
|
|
12
|
+
"""
|
|
13
|
+
createCustomerManagedGroup(customerId: ID!): CustomerManagedGroup!
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
extend type Query {
|
|
17
|
+
ordersForCustomerManagedGroup(customerManagedGroupId: ID!): OrderList!
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const commonSchema: import("graphql").DocumentNode;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commonSchema = void 0;
|
|
4
|
+
const graphql_tag_1 = require("graphql-tag");
|
|
5
|
+
// This is just to enable static codegen, without starting a server
|
|
6
|
+
const scalars = (0, graphql_tag_1.gql) `
|
|
7
|
+
scalar DateTime
|
|
8
|
+
scalar OrderList
|
|
9
|
+
scalar LanguageCode
|
|
10
|
+
scalar JSON
|
|
11
|
+
`;
|
|
12
|
+
exports.commonSchema = (0, graphql_tag_1.gql) `
|
|
13
|
+
type CustomerManagedGroupMember {
|
|
14
|
+
customerId: ID!
|
|
15
|
+
title: String
|
|
16
|
+
addresses: [CustomerManagedGroupAddress!]
|
|
17
|
+
firstName: String!
|
|
18
|
+
lastName: String!
|
|
19
|
+
emailAddress: String!
|
|
20
|
+
isGroupAdministrator: Boolean!
|
|
21
|
+
customFields: JSON
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type CustomerManagedGroupAddress {
|
|
25
|
+
id: ID!
|
|
26
|
+
createdAt: DateTime!
|
|
27
|
+
updatedAt: DateTime!
|
|
28
|
+
fullName: String
|
|
29
|
+
company: String
|
|
30
|
+
streetLine1: String!
|
|
31
|
+
streetLine2: String
|
|
32
|
+
city: String
|
|
33
|
+
province: String
|
|
34
|
+
postalCode: String
|
|
35
|
+
country: CustomerManagedGroupCountry!
|
|
36
|
+
phoneNumber: String
|
|
37
|
+
defaultShippingAddress: Boolean
|
|
38
|
+
defaultBillingAddress: Boolean
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type CustomerManagedGroupCountry {
|
|
42
|
+
id: ID!
|
|
43
|
+
createdAt: DateTime!
|
|
44
|
+
updatedAt: DateTime!
|
|
45
|
+
code: String!
|
|
46
|
+
name: String!
|
|
47
|
+
enabled: Boolean!
|
|
48
|
+
translations: [CustomerManagedGroupCountryTranslation!]!
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type CustomerManagedGroupCountryTranslation {
|
|
52
|
+
id: ID!
|
|
53
|
+
languageCode: LanguageCode!
|
|
54
|
+
name: String!
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type CustomerManagedGroup {
|
|
58
|
+
id: ID!
|
|
59
|
+
createdAt: DateTime!
|
|
60
|
+
updatedAt: DateTime!
|
|
61
|
+
name: String!
|
|
62
|
+
customers: [CustomerManagedGroupMember!]!
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
extend type Mutation {
|
|
66
|
+
makeCustomerAdminOfCustomerManagedGroup(
|
|
67
|
+
groupId: ID!
|
|
68
|
+
customerId: ID!
|
|
69
|
+
): CustomerManagedGroup!
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { ID, Order, PaginatedList, RequestContext } from '@vendure/core';
|
|
2
2
|
import { CustomerManagedGroupsService } from './customer-managed-groups.service';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare class
|
|
3
|
+
import { CustomerManagedGroup, MutationCreateCustomerManagedGroupArgs, MutationMakeCustomerAdminOfCustomerManagedGroupArgs, QueryOrdersForCustomerManagedGroupArgs } from './generated/admin-graphql';
|
|
4
|
+
import { AddCustomerToMyCustomerManagedGroupInput, CustomerManagedGroupMember, UpdateCustomerManagedGroupMemberInput } from './generated/shop-graphql';
|
|
5
|
+
export declare class CustomerManagedGroupsAdminResolver {
|
|
6
|
+
private service;
|
|
7
|
+
constructor(service: CustomerManagedGroupsService);
|
|
8
|
+
ordersForCustomerManagedGroup(ctx: RequestContext, args: QueryOrdersForCustomerManagedGroupArgs): Promise<PaginatedList<Order>>;
|
|
9
|
+
createCustomerManagedGroup(ctx: RequestContext, args: MutationCreateCustomerManagedGroupArgs): Promise<CustomerManagedGroup | undefined>;
|
|
10
|
+
makeCustomerAdminOfCustomerManagedGroup(ctx: RequestContext, args: MutationMakeCustomerAdminOfCustomerManagedGroupArgs): Promise<CustomerManagedGroup>;
|
|
11
|
+
}
|
|
12
|
+
export declare class CustomerManagedGroupsShopResolver {
|
|
6
13
|
private service;
|
|
7
14
|
constructor(service: CustomerManagedGroupsService);
|
|
8
15
|
ordersForMyCustomerManagedGroup(ctx: RequestContext): Promise<PaginatedList<Order>>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CustomerManagedGroupsShopResolver = exports.CustomerManagedGroupsAdminResolver = void 0;
|
|
16
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
17
|
+
const core_1 = require("@vendure/core");
|
|
18
|
+
const customer_managed_groups_service_1 = require("./customer-managed-groups.service");
|
|
19
|
+
let CustomerManagedGroupsAdminResolver = class CustomerManagedGroupsAdminResolver {
|
|
20
|
+
constructor(service) {
|
|
21
|
+
this.service = service;
|
|
22
|
+
}
|
|
23
|
+
ordersForCustomerManagedGroup(ctx, args) {
|
|
24
|
+
return this.service.getOrdersForCustomer(ctx, args.customerManagedGroupId);
|
|
25
|
+
}
|
|
26
|
+
createCustomerManagedGroup(ctx, args) {
|
|
27
|
+
return this.service.createCustomerManagedGroup(ctx, args.customerId);
|
|
28
|
+
}
|
|
29
|
+
makeCustomerAdminOfCustomerManagedGroup(ctx, args) {
|
|
30
|
+
return this.service.makeAdminOfGroup(ctx, args.groupId, args.customerId, true);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, graphql_1.Query)(),
|
|
35
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
36
|
+
__param(0, (0, core_1.Ctx)()),
|
|
37
|
+
__param(1, (0, graphql_1.Args)()),
|
|
38
|
+
__metadata("design:type", Function),
|
|
39
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
40
|
+
__metadata("design:returntype", Promise)
|
|
41
|
+
], CustomerManagedGroupsAdminResolver.prototype, "ordersForCustomerManagedGroup", null);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, graphql_1.Mutation)(),
|
|
44
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
45
|
+
__param(0, (0, core_1.Ctx)()),
|
|
46
|
+
__param(1, (0, graphql_1.Args)()),
|
|
47
|
+
__metadata("design:type", Function),
|
|
48
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
49
|
+
__metadata("design:returntype", Promise)
|
|
50
|
+
], CustomerManagedGroupsAdminResolver.prototype, "createCustomerManagedGroup", null);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, graphql_1.Mutation)(),
|
|
53
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
54
|
+
__param(0, (0, core_1.Ctx)()),
|
|
55
|
+
__param(1, (0, graphql_1.Args)()),
|
|
56
|
+
__metadata("design:type", Function),
|
|
57
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
58
|
+
__metadata("design:returntype", Promise)
|
|
59
|
+
], CustomerManagedGroupsAdminResolver.prototype, "makeCustomerAdminOfCustomerManagedGroup", null);
|
|
60
|
+
CustomerManagedGroupsAdminResolver = __decorate([
|
|
61
|
+
(0, graphql_1.Resolver)(),
|
|
62
|
+
__metadata("design:paramtypes", [customer_managed_groups_service_1.CustomerManagedGroupsService])
|
|
63
|
+
], CustomerManagedGroupsAdminResolver);
|
|
64
|
+
exports.CustomerManagedGroupsAdminResolver = CustomerManagedGroupsAdminResolver;
|
|
65
|
+
let CustomerManagedGroupsShopResolver = class CustomerManagedGroupsShopResolver {
|
|
66
|
+
constructor(service) {
|
|
67
|
+
this.service = service;
|
|
68
|
+
}
|
|
69
|
+
ordersForMyCustomerManagedGroup(ctx) {
|
|
70
|
+
return this.service.getOrdersForCustomer(ctx);
|
|
71
|
+
}
|
|
72
|
+
activeCustomerManagedGroupMember(ctx) {
|
|
73
|
+
return this.service.getActiveMember(ctx);
|
|
74
|
+
}
|
|
75
|
+
myCustomerManagedGroup(ctx) {
|
|
76
|
+
return this.service.myCustomerManagedGroup(ctx);
|
|
77
|
+
}
|
|
78
|
+
createCustomerManagedGroup(ctx) {
|
|
79
|
+
return this.service.createCustomerManagedGroup(ctx);
|
|
80
|
+
}
|
|
81
|
+
makeCustomerAdminOfCustomerManagedGroup(ctx, groupId, customerId) {
|
|
82
|
+
return this.service.makeAdminOfGroup(ctx, groupId, customerId);
|
|
83
|
+
}
|
|
84
|
+
addCustomerToMyCustomerManagedGroup(ctx, input) {
|
|
85
|
+
return this.service.addToGroup(ctx, input);
|
|
86
|
+
}
|
|
87
|
+
updateCustomerManagedGroupMember(ctx, input) {
|
|
88
|
+
return this.service.updateGroupMember(ctx, input);
|
|
89
|
+
}
|
|
90
|
+
removeCustomerFromMyCustomerManagedGroup(ctx, customerId) {
|
|
91
|
+
return this.service.removeFromGroup(ctx, customerId);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, graphql_1.Query)(),
|
|
96
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
97
|
+
__param(0, (0, core_1.Ctx)()),
|
|
98
|
+
__metadata("design:type", Function),
|
|
99
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
100
|
+
__metadata("design:returntype", Promise)
|
|
101
|
+
], CustomerManagedGroupsShopResolver.prototype, "ordersForMyCustomerManagedGroup", null);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, graphql_1.Query)(),
|
|
104
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
105
|
+
__param(0, (0, core_1.Ctx)()),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
108
|
+
__metadata("design:returntype", Promise)
|
|
109
|
+
], CustomerManagedGroupsShopResolver.prototype, "activeCustomerManagedGroupMember", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, graphql_1.Query)(),
|
|
112
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
113
|
+
__param(0, (0, core_1.Ctx)()),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
116
|
+
__metadata("design:returntype", Promise)
|
|
117
|
+
], CustomerManagedGroupsShopResolver.prototype, "myCustomerManagedGroup", null);
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, graphql_1.Mutation)(),
|
|
120
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
121
|
+
__param(0, (0, core_1.Ctx)()),
|
|
122
|
+
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
124
|
+
__metadata("design:returntype", Promise)
|
|
125
|
+
], CustomerManagedGroupsShopResolver.prototype, "createCustomerManagedGroup", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, graphql_1.Mutation)(),
|
|
128
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
129
|
+
__param(0, (0, core_1.Ctx)()),
|
|
130
|
+
__param(1, (0, graphql_1.Args)('groupId')),
|
|
131
|
+
__param(2, (0, graphql_1.Args)('customerId')),
|
|
132
|
+
__metadata("design:type", Function),
|
|
133
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object, Object]),
|
|
134
|
+
__metadata("design:returntype", Promise)
|
|
135
|
+
], CustomerManagedGroupsShopResolver.prototype, "makeCustomerAdminOfCustomerManagedGroup", null);
|
|
136
|
+
__decorate([
|
|
137
|
+
(0, graphql_1.Mutation)(),
|
|
138
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
139
|
+
__param(0, (0, core_1.Ctx)()),
|
|
140
|
+
__param(1, (0, graphql_1.Args)('input')),
|
|
141
|
+
__metadata("design:type", Function),
|
|
142
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
143
|
+
__metadata("design:returntype", Promise)
|
|
144
|
+
], CustomerManagedGroupsShopResolver.prototype, "addCustomerToMyCustomerManagedGroup", null);
|
|
145
|
+
__decorate([
|
|
146
|
+
(0, graphql_1.Mutation)(),
|
|
147
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
148
|
+
__param(0, (0, core_1.Ctx)()),
|
|
149
|
+
__param(1, (0, graphql_1.Args)('input')),
|
|
150
|
+
__metadata("design:type", Function),
|
|
151
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
152
|
+
__metadata("design:returntype", Promise)
|
|
153
|
+
], CustomerManagedGroupsShopResolver.prototype, "updateCustomerManagedGroupMember", null);
|
|
154
|
+
__decorate([
|
|
155
|
+
(0, graphql_1.Mutation)(),
|
|
156
|
+
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
157
|
+
__param(0, (0, core_1.Ctx)()),
|
|
158
|
+
__param(1, (0, graphql_1.Args)('customerId')),
|
|
159
|
+
__metadata("design:type", Function),
|
|
160
|
+
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
161
|
+
__metadata("design:returntype", Promise)
|
|
162
|
+
], CustomerManagedGroupsShopResolver.prototype, "removeCustomerFromMyCustomerManagedGroup", null);
|
|
163
|
+
CustomerManagedGroupsShopResolver = __decorate([
|
|
164
|
+
(0, graphql_1.Resolver)(),
|
|
165
|
+
__metadata("design:paramtypes", [customer_managed_groups_service_1.CustomerManagedGroupsService])
|
|
166
|
+
], CustomerManagedGroupsShopResolver);
|
|
167
|
+
exports.CustomerManagedGroupsShopResolver = CustomerManagedGroupsShopResolver;
|
package/dist/{customer-managed-groups.service.d.ts → api/customer-managed-groups.service.d.ts}
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Customer, CustomerGroupService, CustomerService, EntityHydrator, ID, Order, OrderService, PaginatedList, RequestContext, TransactionalConnection } from '@vendure/core';
|
|
2
2
|
import { CustomerGroupWithCustomFields, CustomerWithCustomFields } from './custom-fields';
|
|
3
|
-
import { AddCustomerToMyCustomerManagedGroupInput,
|
|
3
|
+
import { AddCustomerToMyCustomerManagedGroupInput, UpdateCustomerManagedGroupMemberInput } from './generated/shop-graphql';
|
|
4
|
+
import { CustomerManagedGroup, CustomerManagedGroupMember } from './generated/admin-graphql';
|
|
4
5
|
export declare class CustomerManagedGroupsService {
|
|
5
6
|
private orderService;
|
|
6
7
|
private customerService;
|
|
@@ -8,7 +9,7 @@ export declare class CustomerManagedGroupsService {
|
|
|
8
9
|
private hydrator;
|
|
9
10
|
private transactionalConnection;
|
|
10
11
|
constructor(orderService: OrderService, customerService: CustomerService, customerGroupService: CustomerGroupService, hydrator: EntityHydrator, transactionalConnection: TransactionalConnection);
|
|
11
|
-
getOrdersForCustomer(ctx: RequestContext): Promise<PaginatedList<Order>>;
|
|
12
|
+
getOrdersForCustomer(ctx: RequestContext, customerId?: ID): Promise<PaginatedList<Order>>;
|
|
12
13
|
addToGroup(ctx: RequestContext, { emailAddress: inviteeEmailAddress, isGroupAdmin: inviteeIsAdmin, }: AddCustomerToMyCustomerManagedGroupInput): Promise<CustomerManagedGroup>;
|
|
13
14
|
removeFromGroup(ctx: RequestContext, customerIdToRemove: ID): Promise<CustomerManagedGroup>;
|
|
14
15
|
getOrThrowCustomerByUserId(ctx: RequestContext, userId: ID): Promise<CustomerWithCustomFields>;
|
|
@@ -17,6 +18,10 @@ export declare class CustomerManagedGroupsService {
|
|
|
17
18
|
* Get userId from RequestContext or throw a ForbiddenError if not logged in
|
|
18
19
|
*/
|
|
19
20
|
getOrThrowUserId(ctx: RequestContext): ID;
|
|
21
|
+
/**
|
|
22
|
+
* Get customer from customerId
|
|
23
|
+
*/
|
|
24
|
+
getOrThrowCustomer(ctx: RequestContext, customerId: ID): Promise<Customer>;
|
|
20
25
|
throwIfNotAdministratorOfGroup(userId: ID, group: CustomerGroupWithCustomFields): void;
|
|
21
26
|
isAdministratorOfGroup(userId: ID, group: CustomerGroupWithCustomFields): boolean;
|
|
22
27
|
getCustomerManagedGroup(customer: CustomerWithCustomFields): CustomerGroupWithCustomFields | undefined;
|
|
@@ -26,7 +31,7 @@ export declare class CustomerManagedGroupsService {
|
|
|
26
31
|
getActiveMember(ctx: RequestContext): Promise<CustomerManagedGroupMember | undefined>;
|
|
27
32
|
myCustomerManagedGroup(ctx: RequestContext): Promise<CustomerManagedGroup | undefined>;
|
|
28
33
|
myCustomerManagedGroupWithCustomFields(ctx: RequestContext): Promise<CustomerGroupWithCustomFields | undefined>;
|
|
29
|
-
createCustomerManagedGroup(ctx: RequestContext): Promise<CustomerManagedGroup>;
|
|
34
|
+
createCustomerManagedGroup(ctx: RequestContext, customerId?: ID): Promise<CustomerManagedGroup>;
|
|
30
35
|
/**
|
|
31
36
|
*
|
|
32
37
|
* @param ctx Internal function to create a customer managed group based
|
|
@@ -37,5 +42,5 @@ export declare class CustomerManagedGroupsService {
|
|
|
37
42
|
mapToCustomerManagedGroup(group: CustomerGroupWithCustomFields): CustomerManagedGroup;
|
|
38
43
|
mapToCustomerManagedGroupMember(customer: Customer, isGroupAdministrator: boolean): CustomerManagedGroupMember;
|
|
39
44
|
updateGroupMember(ctx: RequestContext, input: UpdateCustomerManagedGroupMemberInput): Promise<CustomerManagedGroup>;
|
|
40
|
-
makeAdminOfGroup(ctx: RequestContext, groupId: ID, customerId: ID): Promise<CustomerManagedGroup>;
|
|
45
|
+
makeAdminOfGroup(ctx: RequestContext, groupId: ID, customerId: ID, isAdmin?: boolean): Promise<CustomerManagedGroup>;
|
|
41
46
|
}
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CustomerManagedGroupsService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const core_1 = require("@vendure/core");
|
|
15
|
-
const constants_1 = require("
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
16
|
let CustomerManagedGroupsService = class CustomerManagedGroupsService {
|
|
17
17
|
constructor(orderService, customerService, customerGroupService, hydrator, transactionalConnection) {
|
|
18
18
|
this.orderService = orderService;
|
|
@@ -21,14 +21,20 @@ let CustomerManagedGroupsService = class CustomerManagedGroupsService {
|
|
|
21
21
|
this.hydrator = hydrator;
|
|
22
22
|
this.transactionalConnection = transactionalConnection;
|
|
23
23
|
}
|
|
24
|
-
async getOrdersForCustomer(ctx) {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
async getOrdersForCustomer(ctx, customerId) {
|
|
25
|
+
let customer;
|
|
26
|
+
if (customerId) {
|
|
27
|
+
customer = await this.getOrThrowCustomer(ctx, customerId);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const userId = this.getOrThrowUserId(ctx);
|
|
31
|
+
customer = await this.getOrThrowCustomerByUserId(ctx, userId);
|
|
32
|
+
}
|
|
27
33
|
const customerManagedGroup = this.getCustomerManagedGroup(customer);
|
|
28
34
|
if (!customerManagedGroup) {
|
|
29
35
|
throw new core_1.UserInputError(`You are not in a customer managed group`);
|
|
30
36
|
}
|
|
31
|
-
const isAdmin = this.isAdministratorOfGroup(
|
|
37
|
+
const isAdmin = this.isAdministratorOfGroup(customer.user.id, customerManagedGroup);
|
|
32
38
|
const orders = [];
|
|
33
39
|
// If not admin, only fetch orders for the current user
|
|
34
40
|
const customers = isAdmin ? customerManagedGroup.customers : [customer];
|
|
@@ -136,7 +142,7 @@ let CustomerManagedGroupsService = class CustomerManagedGroupsService {
|
|
|
136
142
|
const customerWithGroupsData = await customerRepo
|
|
137
143
|
.createQueryBuilder('customer')
|
|
138
144
|
.leftJoin('customer.channels', 'customer_channel')
|
|
139
|
-
.
|
|
145
|
+
.leftJoinAndSelect('customer.user', 'user')
|
|
140
146
|
.leftJoinAndSelect('customer.addresses', 'customerAddress')
|
|
141
147
|
.leftJoinAndSelect('customerAddress.country', 'customerCountry')
|
|
142
148
|
.leftJoinAndSelect('customer.groups', 'groups')
|
|
@@ -179,6 +185,22 @@ let CustomerManagedGroupsService = class CustomerManagedGroupsService {
|
|
|
179
185
|
}
|
|
180
186
|
return ctx.activeUserId;
|
|
181
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Get customer from customerId
|
|
190
|
+
*/
|
|
191
|
+
async getOrThrowCustomer(ctx, customerId) {
|
|
192
|
+
const customer = await this.customerService.findOne(ctx, customerId, [
|
|
193
|
+
'user',
|
|
194
|
+
'groups',
|
|
195
|
+
'groups.customers',
|
|
196
|
+
'groups.customFields.groupAdmins',
|
|
197
|
+
'groups.customFields.groupAdmins.user',
|
|
198
|
+
]);
|
|
199
|
+
if (!customer) {
|
|
200
|
+
throw new core_1.EntityNotFoundError('Customer', customerId);
|
|
201
|
+
}
|
|
202
|
+
return customer;
|
|
203
|
+
}
|
|
182
204
|
throwIfNotAdministratorOfGroup(userId, group) {
|
|
183
205
|
if (!this.isAdministratorOfGroup(userId, group)) {
|
|
184
206
|
throw new core_1.UserInputError('You are not administrator of your group');
|
|
@@ -222,14 +244,20 @@ let CustomerManagedGroupsService = class CustomerManagedGroupsService {
|
|
|
222
244
|
}
|
|
223
245
|
return customerManagedGroup;
|
|
224
246
|
}
|
|
225
|
-
async createCustomerManagedGroup(ctx) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
247
|
+
async createCustomerManagedGroup(ctx, customerId) {
|
|
248
|
+
let customer;
|
|
249
|
+
if (customerId) {
|
|
250
|
+
customer = await this.getOrThrowCustomer(ctx, customerId);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
const userId = this.getOrThrowUserId(ctx);
|
|
254
|
+
customer = await this.getOrThrowCustomerByUserId(ctx, userId);
|
|
255
|
+
}
|
|
256
|
+
let customerManagedGroup = this.getCustomerManagedGroup(customer);
|
|
229
257
|
if (customerManagedGroup) {
|
|
230
258
|
throw new core_1.UserInputError(`You are already in a customer managed group`);
|
|
231
259
|
}
|
|
232
|
-
customerManagedGroup = await this.createGroup(ctx,
|
|
260
|
+
customerManagedGroup = await this.createGroup(ctx, customer);
|
|
233
261
|
await this.hydrator.hydrate(ctx, customerManagedGroup, {
|
|
234
262
|
relations: ['customers'],
|
|
235
263
|
});
|
|
@@ -338,14 +366,15 @@ let CustomerManagedGroupsService = class CustomerManagedGroupsService {
|
|
|
338
366
|
}
|
|
339
367
|
return newGroupData;
|
|
340
368
|
}
|
|
341
|
-
async makeAdminOfGroup(ctx, groupId, customerId) {
|
|
369
|
+
async makeAdminOfGroup(ctx, groupId, customerId, isAdmin) {
|
|
342
370
|
const customerGroup = await this.customerGroupService.findOne(ctx, groupId, ['customers', 'customers.user']);
|
|
343
371
|
if (!customerGroup ||
|
|
344
372
|
!customerGroup.customFields ||
|
|
345
373
|
!customerGroup.customFields.isCustomerManaged) {
|
|
346
374
|
throw new core_1.UserInputError(`No customer managed group with id ${groupId} exists`);
|
|
347
375
|
}
|
|
348
|
-
if (!
|
|
376
|
+
if (!isAdmin &&
|
|
377
|
+
!customerGroup.customFields.groupAdmins.find((admin) => admin.user?.id === ctx.activeUserId)) {
|
|
349
378
|
throw new core_1.UserInputError(`You are not admin of this customer managed group`);
|
|
350
379
|
}
|
|
351
380
|
const customerInQuestion = await customerGroup.customers.find((c) => c.id === customerId);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export type Maybe<T> = T | null;
|
|
2
|
+
export type InputMaybe<T> = Maybe<T>;
|
|
3
|
+
export type Exact<T extends {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}> = {
|
|
6
|
+
[K in keyof T]: T[K];
|
|
7
|
+
};
|
|
8
|
+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
9
|
+
[SubKey in K]?: Maybe<T[SubKey]>;
|
|
10
|
+
};
|
|
11
|
+
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
12
|
+
[SubKey in K]: Maybe<T[SubKey]>;
|
|
13
|
+
};
|
|
14
|
+
/** All built-in and custom scalars, mapped to their actual values */
|
|
15
|
+
export type Scalars = {
|
|
16
|
+
ID: string | number;
|
|
17
|
+
String: string;
|
|
18
|
+
Boolean: boolean;
|
|
19
|
+
Int: number;
|
|
20
|
+
Float: number;
|
|
21
|
+
DateTime: any;
|
|
22
|
+
JSON: any;
|
|
23
|
+
LanguageCode: any;
|
|
24
|
+
OrderList: any;
|
|
25
|
+
};
|
|
26
|
+
export type CustomerManagedGroup = {
|
|
27
|
+
__typename?: 'CustomerManagedGroup';
|
|
28
|
+
createdAt: Scalars['DateTime'];
|
|
29
|
+
customers: Array<CustomerManagedGroupMember>;
|
|
30
|
+
id: Scalars['ID'];
|
|
31
|
+
name: Scalars['String'];
|
|
32
|
+
updatedAt: Scalars['DateTime'];
|
|
33
|
+
};
|
|
34
|
+
export type CustomerManagedGroupAddress = {
|
|
35
|
+
__typename?: 'CustomerManagedGroupAddress';
|
|
36
|
+
city?: Maybe<Scalars['String']>;
|
|
37
|
+
company?: Maybe<Scalars['String']>;
|
|
38
|
+
country: CustomerManagedGroupCountry;
|
|
39
|
+
createdAt: Scalars['DateTime'];
|
|
40
|
+
defaultBillingAddress?: Maybe<Scalars['Boolean']>;
|
|
41
|
+
defaultShippingAddress?: Maybe<Scalars['Boolean']>;
|
|
42
|
+
fullName?: Maybe<Scalars['String']>;
|
|
43
|
+
id: Scalars['ID'];
|
|
44
|
+
phoneNumber?: Maybe<Scalars['String']>;
|
|
45
|
+
postalCode?: Maybe<Scalars['String']>;
|
|
46
|
+
province?: Maybe<Scalars['String']>;
|
|
47
|
+
streetLine1: Scalars['String'];
|
|
48
|
+
streetLine2?: Maybe<Scalars['String']>;
|
|
49
|
+
updatedAt: Scalars['DateTime'];
|
|
50
|
+
};
|
|
51
|
+
export type CustomerManagedGroupCountry = {
|
|
52
|
+
__typename?: 'CustomerManagedGroupCountry';
|
|
53
|
+
code: Scalars['String'];
|
|
54
|
+
createdAt: Scalars['DateTime'];
|
|
55
|
+
enabled: Scalars['Boolean'];
|
|
56
|
+
id: Scalars['ID'];
|
|
57
|
+
name: Scalars['String'];
|
|
58
|
+
translations: Array<CustomerManagedGroupCountryTranslation>;
|
|
59
|
+
updatedAt: Scalars['DateTime'];
|
|
60
|
+
};
|
|
61
|
+
export type CustomerManagedGroupCountryTranslation = {
|
|
62
|
+
__typename?: 'CustomerManagedGroupCountryTranslation';
|
|
63
|
+
id: Scalars['ID'];
|
|
64
|
+
languageCode: Scalars['LanguageCode'];
|
|
65
|
+
name: Scalars['String'];
|
|
66
|
+
};
|
|
67
|
+
export type CustomerManagedGroupMember = {
|
|
68
|
+
__typename?: 'CustomerManagedGroupMember';
|
|
69
|
+
addresses?: Maybe<Array<CustomerManagedGroupAddress>>;
|
|
70
|
+
customFields?: Maybe<Scalars['JSON']>;
|
|
71
|
+
customerId: Scalars['ID'];
|
|
72
|
+
emailAddress: Scalars['String'];
|
|
73
|
+
firstName: Scalars['String'];
|
|
74
|
+
isGroupAdministrator: Scalars['Boolean'];
|
|
75
|
+
lastName: Scalars['String'];
|
|
76
|
+
title?: Maybe<Scalars['String']>;
|
|
77
|
+
};
|
|
78
|
+
export type Mutation = {
|
|
79
|
+
__typename?: 'Mutation';
|
|
80
|
+
/** Create an empty group with the specified customer as Administrator */
|
|
81
|
+
createCustomerManagedGroup: CustomerManagedGroup;
|
|
82
|
+
makeCustomerAdminOfCustomerManagedGroup: CustomerManagedGroup;
|
|
83
|
+
};
|
|
84
|
+
export type MutationCreateCustomerManagedGroupArgs = {
|
|
85
|
+
customerId: Scalars['ID'];
|
|
86
|
+
};
|
|
87
|
+
export type MutationMakeCustomerAdminOfCustomerManagedGroupArgs = {
|
|
88
|
+
customerId: Scalars['ID'];
|
|
89
|
+
groupId: Scalars['ID'];
|
|
90
|
+
};
|
|
91
|
+
export type Query = {
|
|
92
|
+
__typename?: 'Query';
|
|
93
|
+
ordersForCustomerManagedGroup: Scalars['OrderList'];
|
|
94
|
+
};
|
|
95
|
+
export type QueryOrdersForCustomerManagedGroupArgs = {
|
|
96
|
+
customerManagedGroupId: Scalars['ID'];
|
|
97
|
+
};
|
|
@@ -13,7 +13,7 @@ export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
|
13
13
|
};
|
|
14
14
|
/** All built-in and custom scalars, mapped to their actual values */
|
|
15
15
|
export type Scalars = {
|
|
16
|
-
ID:
|
|
16
|
+
ID: string | number;
|
|
17
17
|
String: string;
|
|
18
18
|
Boolean: boolean;
|
|
19
19
|
Int: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const shopSchema: import("graphql").DocumentNode;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shopSchema = void 0;
|
|
4
|
+
const graphql_tag_1 = require("graphql-tag");
|
|
5
|
+
const common_graphql_1 = require("./common-graphql");
|
|
6
|
+
exports.shopSchema = (0, graphql_tag_1.gql) `
|
|
7
|
+
${common_graphql_1.commonSchema}
|
|
8
|
+
|
|
9
|
+
input AddCustomerToMyCustomerManagedGroupInput {
|
|
10
|
+
emailAddress: String!
|
|
11
|
+
isGroupAdmin: Boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
input UpdateCustomerManagedGroupMemberInput {
|
|
15
|
+
title: String
|
|
16
|
+
firstName: String
|
|
17
|
+
lastName: String
|
|
18
|
+
emailAddress: String
|
|
19
|
+
addresses: [CustomerManagedGroupAddressInput!]
|
|
20
|
+
customerId: ID!
|
|
21
|
+
customFields: JSON
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
When no ID is given, a new address will be created
|
|
26
|
+
"""
|
|
27
|
+
input CustomerManagedGroupAddressInput {
|
|
28
|
+
id: ID
|
|
29
|
+
fullName: String
|
|
30
|
+
company: String
|
|
31
|
+
streetLine1: String
|
|
32
|
+
streetLine2: String
|
|
33
|
+
city: String
|
|
34
|
+
province: String
|
|
35
|
+
postalCode: String
|
|
36
|
+
countryCode: String
|
|
37
|
+
phoneNumber: String
|
|
38
|
+
defaultShippingAddress: Boolean
|
|
39
|
+
defaultBillingAddress: Boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
extend type Mutation {
|
|
43
|
+
"""
|
|
44
|
+
Creates a group with the current logged in user as administrator of the group
|
|
45
|
+
"""
|
|
46
|
+
addCustomerToMyCustomerManagedGroup(
|
|
47
|
+
input: AddCustomerToMyCustomerManagedGroupInput
|
|
48
|
+
): CustomerManagedGroup!
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
Create an empty group with the current user as Administrator
|
|
52
|
+
"""
|
|
53
|
+
createCustomerManagedGroup: CustomerManagedGroup!
|
|
54
|
+
|
|
55
|
+
removeCustomerFromMyCustomerManagedGroup(
|
|
56
|
+
customerId: ID!
|
|
57
|
+
): CustomerManagedGroup!
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
Update a member of one's group
|
|
61
|
+
"""
|
|
62
|
+
updateCustomerManagedGroupMember(
|
|
63
|
+
input: UpdateCustomerManagedGroupMemberInput!
|
|
64
|
+
): CustomerManagedGroup!
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
extend type Query {
|
|
68
|
+
"""
|
|
69
|
+
Fetch placed orders for each member of the group
|
|
70
|
+
"""
|
|
71
|
+
ordersForMyCustomerManagedGroup: OrderList!
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
Fetch the current logged in group member
|
|
75
|
+
"""
|
|
76
|
+
activeCustomerManagedGroupMember: CustomerManagedGroupMember
|
|
77
|
+
|
|
78
|
+
myCustomerManagedGroup: CustomerManagedGroup
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
@@ -12,9 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CustomerManagedGroupsPlugin = void 0;
|
|
13
13
|
const core_1 = require("@vendure/core");
|
|
14
14
|
const path_1 = __importDefault(require("path"));
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
const shop_graphql_1 = require("./api/shop-graphql");
|
|
16
|
+
const admin_graphql_1 = require("./api/admin-graphql");
|
|
17
|
+
const custom_fields_1 = require("./api/custom-fields");
|
|
18
|
+
const customer_managed_groups_service_1 = require("./api/customer-managed-groups.service");
|
|
19
|
+
const customer_managed_groups_resolver_1 = require("./api/customer-managed-groups.resolver");
|
|
18
20
|
let CustomerManagedGroupsPlugin = class CustomerManagedGroupsPlugin {
|
|
19
21
|
};
|
|
20
22
|
CustomerManagedGroupsPlugin.ui = {
|
|
@@ -31,9 +33,13 @@ CustomerManagedGroupsPlugin = __decorate([
|
|
|
31
33
|
(0, core_1.VendurePlugin)({
|
|
32
34
|
imports: [core_1.PluginCommonModule],
|
|
33
35
|
providers: [customer_managed_groups_service_1.CustomerManagedGroupsService],
|
|
36
|
+
adminApiExtensions: {
|
|
37
|
+
resolvers: [customer_managed_groups_resolver_1.CustomerManagedGroupsAdminResolver],
|
|
38
|
+
schema: admin_graphql_1.adminSchema,
|
|
39
|
+
},
|
|
34
40
|
shopApiExtensions: {
|
|
35
|
-
resolvers: [
|
|
36
|
-
schema:
|
|
41
|
+
resolvers: [customer_managed_groups_resolver_1.CustomerManagedGroupsShopResolver],
|
|
42
|
+
schema: shop_graphql_1.shopSchema,
|
|
37
43
|
},
|
|
38
44
|
configuration: (config) => {
|
|
39
45
|
config.customFields = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './customer-managed-groups.plugin';
|
|
2
|
-
export * from './customer-managed-groups.service';
|
|
3
|
-
export * from './api-
|
|
4
|
-
export * from './
|
|
2
|
+
export * from './api/customer-managed-groups.service';
|
|
3
|
+
export * from './api/shop-graphql';
|
|
4
|
+
export * from './api/admin-graphql';
|
|
5
|
+
export * from './api/custom-fields';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./customer-managed-groups.plugin"), exports);
|
|
18
|
-
__exportStar(require("./customer-managed-groups.service"), exports);
|
|
19
|
-
__exportStar(require("./api-
|
|
20
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./api/customer-managed-groups.service"), exports);
|
|
19
|
+
__exportStar(require("./api/shop-graphql"), exports);
|
|
20
|
+
__exportStar(require("./api/admin-graphql"), exports);
|
|
21
|
+
__exportStar(require("./api/custom-fields"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinelab/vendure-plugin-customer-managed-groups",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "This plugin allows customer groups to have 'Group admins', that are allowed to fetch placed orders for everyone in the group.",
|
|
5
|
+
"icon": "account-group",
|
|
5
6
|
"author": "Martijn van de Brug <martijn@pinelab.studio>",
|
|
6
7
|
"homepage": "https://pinelab-plugins.com/",
|
|
7
8
|
"repository": "https://github.com/Pinelab-studio/pinelab-vendure-plugins",
|
|
@@ -17,12 +18,13 @@
|
|
|
17
18
|
"types": "dist/index.d.ts",
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
20
|
-
"README.md"
|
|
21
|
+
"README.md",
|
|
22
|
+
"CHANGELOG.md"
|
|
21
23
|
],
|
|
22
24
|
"scripts": {
|
|
23
25
|
"start": "yarn ts-node test/dev-server.ts",
|
|
24
26
|
"build": "rimraf dist && yarn graphql-codegen && tsc",
|
|
25
27
|
"test": "vitest run"
|
|
26
28
|
},
|
|
27
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "6d6a0d90258221ca3331996e6fc9a0990b8d5bfc"
|
|
28
30
|
}
|
package/dist/api-extensions.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.CustomerManagedGroupsResolver = exports.shopSchema = void 0;
|
|
16
|
-
const graphql_1 = require("@nestjs/graphql");
|
|
17
|
-
const core_1 = require("@vendure/core");
|
|
18
|
-
const graphql_tag_1 = require("graphql-tag");
|
|
19
|
-
const customer_managed_groups_service_1 = require("./customer-managed-groups.service");
|
|
20
|
-
// This is just to enable static codegen, without starting a server
|
|
21
|
-
const scalars = (0, graphql_tag_1.gql) `
|
|
22
|
-
scalar DateTime
|
|
23
|
-
scalar OrderList
|
|
24
|
-
scalar LanguageCode
|
|
25
|
-
scalar JSON
|
|
26
|
-
`;
|
|
27
|
-
exports.shopSchema = (0, graphql_tag_1.gql) `
|
|
28
|
-
input AddCustomerToMyCustomerManagedGroupInput {
|
|
29
|
-
emailAddress: String!
|
|
30
|
-
isGroupAdmin: Boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
input UpdateCustomerManagedGroupMemberInput {
|
|
34
|
-
title: String
|
|
35
|
-
firstName: String
|
|
36
|
-
lastName: String
|
|
37
|
-
emailAddress: String
|
|
38
|
-
addresses: [CustomerManagedGroupAddressInput!]
|
|
39
|
-
customerId: ID!
|
|
40
|
-
customFields: JSON
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
"""
|
|
44
|
-
When no ID is given, a new address will be created
|
|
45
|
-
"""
|
|
46
|
-
input CustomerManagedGroupAddressInput {
|
|
47
|
-
id: ID
|
|
48
|
-
fullName: String
|
|
49
|
-
company: String
|
|
50
|
-
streetLine1: String
|
|
51
|
-
streetLine2: String
|
|
52
|
-
city: String
|
|
53
|
-
province: String
|
|
54
|
-
postalCode: String
|
|
55
|
-
countryCode: String
|
|
56
|
-
phoneNumber: String
|
|
57
|
-
defaultShippingAddress: Boolean
|
|
58
|
-
defaultBillingAddress: Boolean
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type CustomerManagedGroupMember {
|
|
62
|
-
customerId: ID!
|
|
63
|
-
title: String
|
|
64
|
-
addresses: [CustomerManagedGroupAddress!]
|
|
65
|
-
firstName: String!
|
|
66
|
-
lastName: String!
|
|
67
|
-
emailAddress: String!
|
|
68
|
-
isGroupAdministrator: Boolean!
|
|
69
|
-
customFields: JSON
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
type CustomerManagedGroupAddress {
|
|
73
|
-
id: ID!
|
|
74
|
-
createdAt: DateTime!
|
|
75
|
-
updatedAt: DateTime!
|
|
76
|
-
fullName: String
|
|
77
|
-
company: String
|
|
78
|
-
streetLine1: String!
|
|
79
|
-
streetLine2: String
|
|
80
|
-
city: String
|
|
81
|
-
province: String
|
|
82
|
-
postalCode: String
|
|
83
|
-
country: CustomerManagedGroupCountry!
|
|
84
|
-
phoneNumber: String
|
|
85
|
-
defaultShippingAddress: Boolean
|
|
86
|
-
defaultBillingAddress: Boolean
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
type CustomerManagedGroupCountry {
|
|
90
|
-
id: ID!
|
|
91
|
-
createdAt: DateTime!
|
|
92
|
-
updatedAt: DateTime!
|
|
93
|
-
code: String!
|
|
94
|
-
name: String!
|
|
95
|
-
enabled: Boolean!
|
|
96
|
-
translations: [CustomerManagedGroupCountryTranslation!]!
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
type CustomerManagedGroupCountryTranslation {
|
|
100
|
-
id: ID!
|
|
101
|
-
languageCode: LanguageCode!
|
|
102
|
-
name: String!
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
type CustomerManagedGroup {
|
|
106
|
-
id: ID!
|
|
107
|
-
createdAt: DateTime!
|
|
108
|
-
updatedAt: DateTime!
|
|
109
|
-
name: String!
|
|
110
|
-
customers: [CustomerManagedGroupMember!]!
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
extend type Mutation {
|
|
114
|
-
"""
|
|
115
|
-
Creates a group with the current logged in user as administrator of the group
|
|
116
|
-
"""
|
|
117
|
-
addCustomerToMyCustomerManagedGroup(
|
|
118
|
-
input: AddCustomerToMyCustomerManagedGroupInput
|
|
119
|
-
): CustomerManagedGroup!
|
|
120
|
-
"""
|
|
121
|
-
Create an empty group with the current user as Administrator
|
|
122
|
-
"""
|
|
123
|
-
createCustomerManagedGroup: CustomerManagedGroup!
|
|
124
|
-
|
|
125
|
-
removeCustomerFromMyCustomerManagedGroup(
|
|
126
|
-
customerId: ID!
|
|
127
|
-
): CustomerManagedGroup!
|
|
128
|
-
|
|
129
|
-
"""
|
|
130
|
-
Update a member of one's group
|
|
131
|
-
"""
|
|
132
|
-
updateCustomerManagedGroupMember(
|
|
133
|
-
input: UpdateCustomerManagedGroupMemberInput!
|
|
134
|
-
): CustomerManagedGroup!
|
|
135
|
-
makeCustomerAdminOfCustomerManagedGroup(
|
|
136
|
-
groupId: ID!
|
|
137
|
-
customerId: ID!
|
|
138
|
-
): CustomerManagedGroup!
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
extend type Query {
|
|
142
|
-
"""
|
|
143
|
-
Fetch placed orders for each member of the group
|
|
144
|
-
"""
|
|
145
|
-
ordersForMyCustomerManagedGroup: OrderList!
|
|
146
|
-
"""
|
|
147
|
-
Fetch the current logged in group member
|
|
148
|
-
"""
|
|
149
|
-
activeCustomerManagedGroupMember: CustomerManagedGroupMember
|
|
150
|
-
|
|
151
|
-
myCustomerManagedGroup: CustomerManagedGroup
|
|
152
|
-
}
|
|
153
|
-
`;
|
|
154
|
-
let CustomerManagedGroupsResolver = class CustomerManagedGroupsResolver {
|
|
155
|
-
constructor(service) {
|
|
156
|
-
this.service = service;
|
|
157
|
-
}
|
|
158
|
-
async ordersForMyCustomerManagedGroup(ctx) {
|
|
159
|
-
return this.service.getOrdersForCustomer(ctx);
|
|
160
|
-
}
|
|
161
|
-
async activeCustomerManagedGroupMember(ctx) {
|
|
162
|
-
return this.service.getActiveMember(ctx);
|
|
163
|
-
}
|
|
164
|
-
async myCustomerManagedGroup(ctx) {
|
|
165
|
-
return this.service.myCustomerManagedGroup(ctx);
|
|
166
|
-
}
|
|
167
|
-
async createCustomerManagedGroup(ctx) {
|
|
168
|
-
return this.service.createCustomerManagedGroup(ctx);
|
|
169
|
-
}
|
|
170
|
-
async makeCustomerAdminOfCustomerManagedGroup(ctx, groupId, customerId) {
|
|
171
|
-
return this.service.makeAdminOfGroup(ctx, groupId, customerId);
|
|
172
|
-
}
|
|
173
|
-
async addCustomerToMyCustomerManagedGroup(ctx, input) {
|
|
174
|
-
return this.service.addToGroup(ctx, input);
|
|
175
|
-
}
|
|
176
|
-
async updateCustomerManagedGroupMember(ctx, input) {
|
|
177
|
-
return this.service.updateGroupMember(ctx, input);
|
|
178
|
-
}
|
|
179
|
-
async removeCustomerFromMyCustomerManagedGroup(ctx, customerId) {
|
|
180
|
-
return this.service.removeFromGroup(ctx, customerId);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
__decorate([
|
|
184
|
-
(0, graphql_1.Query)(),
|
|
185
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
186
|
-
__param(0, (0, core_1.Ctx)()),
|
|
187
|
-
__metadata("design:type", Function),
|
|
188
|
-
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
189
|
-
__metadata("design:returntype", Promise)
|
|
190
|
-
], CustomerManagedGroupsResolver.prototype, "ordersForMyCustomerManagedGroup", null);
|
|
191
|
-
__decorate([
|
|
192
|
-
(0, graphql_1.Query)(),
|
|
193
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
194
|
-
__param(0, (0, core_1.Ctx)()),
|
|
195
|
-
__metadata("design:type", Function),
|
|
196
|
-
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
197
|
-
__metadata("design:returntype", Promise)
|
|
198
|
-
], CustomerManagedGroupsResolver.prototype, "activeCustomerManagedGroupMember", null);
|
|
199
|
-
__decorate([
|
|
200
|
-
(0, graphql_1.Query)(),
|
|
201
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
202
|
-
__param(0, (0, core_1.Ctx)()),
|
|
203
|
-
__metadata("design:type", Function),
|
|
204
|
-
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
205
|
-
__metadata("design:returntype", Promise)
|
|
206
|
-
], CustomerManagedGroupsResolver.prototype, "myCustomerManagedGroup", null);
|
|
207
|
-
__decorate([
|
|
208
|
-
(0, graphql_1.Mutation)(),
|
|
209
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
210
|
-
__param(0, (0, core_1.Ctx)()),
|
|
211
|
-
__metadata("design:type", Function),
|
|
212
|
-
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
213
|
-
__metadata("design:returntype", Promise)
|
|
214
|
-
], CustomerManagedGroupsResolver.prototype, "createCustomerManagedGroup", null);
|
|
215
|
-
__decorate([
|
|
216
|
-
(0, graphql_1.Mutation)(),
|
|
217
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
218
|
-
__param(0, (0, core_1.Ctx)()),
|
|
219
|
-
__param(1, (0, graphql_1.Args)('groupId')),
|
|
220
|
-
__param(2, (0, graphql_1.Args)('customerId')),
|
|
221
|
-
__metadata("design:type", Function),
|
|
222
|
-
__metadata("design:paramtypes", [core_1.RequestContext, Object, Object]),
|
|
223
|
-
__metadata("design:returntype", Promise)
|
|
224
|
-
], CustomerManagedGroupsResolver.prototype, "makeCustomerAdminOfCustomerManagedGroup", null);
|
|
225
|
-
__decorate([
|
|
226
|
-
(0, graphql_1.Mutation)(),
|
|
227
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
228
|
-
__param(0, (0, core_1.Ctx)()),
|
|
229
|
-
__param(1, (0, graphql_1.Args)('input')),
|
|
230
|
-
__metadata("design:type", Function),
|
|
231
|
-
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
232
|
-
__metadata("design:returntype", Promise)
|
|
233
|
-
], CustomerManagedGroupsResolver.prototype, "addCustomerToMyCustomerManagedGroup", null);
|
|
234
|
-
__decorate([
|
|
235
|
-
(0, graphql_1.Mutation)(),
|
|
236
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
237
|
-
__param(0, (0, core_1.Ctx)()),
|
|
238
|
-
__param(1, (0, graphql_1.Args)('input')),
|
|
239
|
-
__metadata("design:type", Function),
|
|
240
|
-
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
241
|
-
__metadata("design:returntype", Promise)
|
|
242
|
-
], CustomerManagedGroupsResolver.prototype, "updateCustomerManagedGroupMember", null);
|
|
243
|
-
__decorate([
|
|
244
|
-
(0, graphql_1.Mutation)(),
|
|
245
|
-
(0, core_1.Allow)(core_1.Permission.Authenticated),
|
|
246
|
-
__param(0, (0, core_1.Ctx)()),
|
|
247
|
-
__param(1, (0, graphql_1.Args)('customerId')),
|
|
248
|
-
__metadata("design:type", Function),
|
|
249
|
-
__metadata("design:paramtypes", [core_1.RequestContext, Object]),
|
|
250
|
-
__metadata("design:returntype", Promise)
|
|
251
|
-
], CustomerManagedGroupsResolver.prototype, "removeCustomerFromMyCustomerManagedGroup", null);
|
|
252
|
-
CustomerManagedGroupsResolver = __decorate([
|
|
253
|
-
(0, graphql_1.Resolver)(),
|
|
254
|
-
__metadata("design:paramtypes", [customer_managed_groups_service_1.CustomerManagedGroupsService])
|
|
255
|
-
], CustomerManagedGroupsResolver);
|
|
256
|
-
exports.CustomerManagedGroupsResolver = CustomerManagedGroupsResolver;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|