@things-factory/quotation 10.1.124 → 10.1.128
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/dist-client/bootstrap.js +1 -7
- package/dist-client/bootstrap.js.map +1 -1
- package/dist-client/index.d.ts +2 -1
- package/dist-client/index.js +2 -1
- package/dist-client/index.js.map +1 -1
- package/dist-client/pages/quotation-editor.d.ts +43 -0
- package/dist-client/pages/quotation-editor.js +313 -0
- package/dist-client/pages/quotation-editor.js.map +1 -0
- package/dist-client/pages/quotation-list.d.ts +36 -0
- package/dist-client/pages/quotation-list.js +113 -0
- package/dist-client/pages/quotation-list.js.map +1 -0
- package/dist-client/quotation-attach.d.ts +16 -0
- package/dist-client/quotation-attach.js +8 -0
- package/dist-client/quotation-attach.js.map +1 -0
- package/dist-client/quotation-words.d.ts +1 -0
- package/dist-client/quotation-words.js +13 -0
- package/dist-client/quotation-words.js.map +1 -0
- package/dist-client/route.d.ts +1 -1
- package/dist-client/route.js +4 -4
- package/dist-client/route.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/index.d.ts +1 -0
- package/dist-server/index.js +1 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/index.d.ts +8 -3
- package/dist-server/service/index.js +9 -17
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/quotation/index.d.ts +8 -5
- package/dist-server/service/quotation/index.js +8 -6
- package/dist-server/service/quotation/index.js.map +1 -1
- package/dist-server/service/quotation/quotation-event-query.d.ts +9 -0
- package/dist-server/service/quotation/quotation-event-query.js +55 -0
- package/dist-server/service/quotation/quotation-event-query.js.map +1 -0
- package/dist-server/service/quotation/quotation-event.d.ts +22 -0
- package/dist-server/service/quotation/quotation-event.js +98 -0
- package/dist-server/service/quotation/quotation-event.js.map +1 -0
- package/dist-server/service/quotation/quotation-item-query.d.ts +8 -0
- package/dist-server/service/quotation/quotation-item-query.js +45 -0
- package/dist-server/service/quotation/quotation-item-query.js.map +1 -0
- package/dist-server/service/quotation/quotation-item.d.ts +18 -0
- package/dist-server/service/quotation/quotation-item.js +75 -0
- package/dist-server/service/quotation/quotation-item.js.map +1 -0
- package/dist-server/service/quotation/quotation-mutation.d.ts +7 -6
- package/dist-server/service/quotation/quotation-mutation.js +66 -140
- package/dist-server/service/quotation/quotation-mutation.js.map +1 -1
- package/dist-server/service/quotation/quotation-query.d.ts +10 -5
- package/dist-server/service/quotation/quotation-query.js +69 -41
- package/dist-server/service/quotation/quotation-query.js.map +1 -1
- package/dist-server/service/quotation/quotation-rules.d.ts +6 -0
- package/dist-server/service/quotation/quotation-rules.js +22 -0
- package/dist-server/service/quotation/quotation-rules.js.map +1 -0
- package/dist-server/service/quotation/quotation-service.d.ts +23 -0
- package/dist-server/service/quotation/quotation-service.js +114 -0
- package/dist-server/service/quotation/quotation-service.js.map +1 -0
- package/dist-server/service/quotation/quotation-type.d.ts +4 -18
- package/dist-server/service/quotation/quotation-type.js +9 -63
- package/dist-server/service/quotation/quotation-type.js.map +1 -1
- package/dist-server/service/quotation/quotation.d.ts +19 -11
- package/dist-server/service/quotation/quotation.js +41 -44
- package/dist-server/service/quotation/quotation.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -6
- package/things-factory.config.js +2 -2
- package/translations/en.json +36 -1
- package/translations/ko.json +36 -1
- package/dist-client/actions/main.d.ts +0 -1
- package/dist-client/actions/main.js +0 -2
- package/dist-client/actions/main.js.map +0 -1
- package/dist-client/activities/activity-quotation-edit.d.ts +0 -14
- package/dist-client/activities/activity-quotation-edit.js +0 -87
- package/dist-client/activities/activity-quotation-edit.js.map +0 -1
- package/dist-client/activities/activity-quotation-view.d.ts +0 -14
- package/dist-client/activities/activity-quotation-view.js +0 -87
- package/dist-client/activities/activity-quotation-view.js.map +0 -1
- package/dist-client/pages/main.d.ts +0 -1
- package/dist-client/pages/main.js +0 -36
- package/dist-client/pages/main.js.map +0 -1
- package/dist-client/pages/quotation/quotation-importer.d.ts +0 -23
- package/dist-client/pages/quotation/quotation-importer.js +0 -93
- package/dist-client/pages/quotation/quotation-importer.js.map +0 -1
- package/dist-client/pages/quotation/quotation-list-page.d.ts +0 -55
- package/dist-client/pages/quotation/quotation-list-page.js +0 -262
- package/dist-client/pages/quotation/quotation-list-page.js.map +0 -1
- package/dist-client/reducers/main.d.ts +0 -6
- package/dist-client/reducers/main.js +0 -14
- package/dist-client/reducers/main.js.map +0 -1
- package/dist-server/activities/activity-quotation.d.ts +0 -42
- package/dist-server/activities/activity-quotation.js +0 -114
- package/dist-server/activities/activity-quotation.js.map +0 -1
- package/dist-server/activities/index.d.ts +0 -1
- package/dist-server/activities/index.js +0 -17
- package/dist-server/activities/index.js.map +0 -1
- package/dist-server/service/quotation/event-subscriber.d.ts +0 -7
- package/dist-server/service/quotation/event-subscriber.js +0 -21
- package/dist-server/service/quotation/event-subscriber.js.map +0 -1
- package/dist-server/service/quotation/quotation-history.d.ts +0 -25
- package/dist-server/service/quotation/quotation-history.js +0 -132
- package/dist-server/service/quotation/quotation-history.js.map +0 -1
|
@@ -2,190 +2,116 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuotationMutation = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const shell_1 = require("@things-factory/shell");
|
|
5
6
|
const type_graphql_1 = require("type-graphql");
|
|
6
|
-
const typeorm_1 = require("typeorm");
|
|
7
|
-
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
8
7
|
const quotation_1 = require("./quotation");
|
|
8
|
+
const quotation_service_1 = require("./quotation-service");
|
|
9
9
|
const quotation_type_1 = require("./quotation-type");
|
|
10
10
|
let QuotationMutation = class QuotationMutation {
|
|
11
|
-
|
|
12
|
-
const { domain, user
|
|
13
|
-
|
|
14
|
-
...quotation,
|
|
15
|
-
domain,
|
|
16
|
-
creator: user,
|
|
17
|
-
updater: user
|
|
18
|
-
});
|
|
19
|
-
if (quotation.thumbnail) {
|
|
20
|
-
await (0, attachment_base_1.createAttachment)(null, {
|
|
21
|
-
attachment: {
|
|
22
|
-
file: quotation.thumbnail,
|
|
23
|
-
refType: quotation_1.Quotation.name,
|
|
24
|
-
refBy: result.id
|
|
25
|
-
}
|
|
26
|
-
}, context);
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
11
|
+
createQuotation(quotation, context) {
|
|
12
|
+
const { tx, domain, user } = context.state;
|
|
13
|
+
return (0, quotation_service_1.saveQuotation)(tx, domain, user, quotation);
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
const { domain, user
|
|
32
|
-
|
|
33
|
-
const quotation = await repository.findOne({
|
|
34
|
-
where: { domain: { id: domain.id }, id }
|
|
35
|
-
});
|
|
36
|
-
const result = await repository.save({
|
|
37
|
-
...quotation,
|
|
38
|
-
...patch,
|
|
39
|
-
updater: user
|
|
40
|
-
});
|
|
41
|
-
if (patch.thumbnail) {
|
|
42
|
-
await (0, attachment_base_1.deleteAttachmentsByRef)(null, { refBys: [result.id] }, context);
|
|
43
|
-
await (0, attachment_base_1.createAttachment)(null, {
|
|
44
|
-
attachment: {
|
|
45
|
-
file: patch.thumbnail,
|
|
46
|
-
refType: quotation_1.Quotation.name,
|
|
47
|
-
refBy: result.id
|
|
48
|
-
}
|
|
49
|
-
}, context);
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
15
|
+
updateQuotation(id, quotation, context) {
|
|
16
|
+
const { tx, domain, user } = context.state;
|
|
17
|
+
return (0, quotation_service_1.saveQuotation)(tx, domain, user, quotation, id);
|
|
52
18
|
}
|
|
53
|
-
|
|
54
|
-
const { domain, user
|
|
55
|
-
|
|
56
|
-
const _createRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === '+');
|
|
57
|
-
const _updateRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === 'M');
|
|
58
|
-
const quotationRepo = tx.getRepository(quotation_1.Quotation);
|
|
59
|
-
if (_createRecords.length > 0) {
|
|
60
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
61
|
-
const newRecord = _createRecords[i];
|
|
62
|
-
const result = await quotationRepo.save({
|
|
63
|
-
...newRecord,
|
|
64
|
-
domain,
|
|
65
|
-
creator: user,
|
|
66
|
-
updater: user
|
|
67
|
-
});
|
|
68
|
-
if (newRecord.thumbnail) {
|
|
69
|
-
await (0, attachment_base_1.createAttachment)(null, {
|
|
70
|
-
attachment: {
|
|
71
|
-
file: newRecord.thumbnail,
|
|
72
|
-
refType: quotation_1.Quotation.name,
|
|
73
|
-
refBy: result.id
|
|
74
|
-
}
|
|
75
|
-
}, context);
|
|
76
|
-
}
|
|
77
|
-
results.push({ ...result, cuFlag: '+' });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (_updateRecords.length > 0) {
|
|
81
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
82
|
-
const updateRecord = _updateRecords[i];
|
|
83
|
-
const quotation = await quotationRepo.findOne({
|
|
84
|
-
where: { domain: { id: domain.id }, id: updateRecord.id }
|
|
85
|
-
});
|
|
86
|
-
if (!quotation) {
|
|
87
|
-
throw new Error(`failed to find quotation to update: ${updateRecord.id}`);
|
|
88
|
-
}
|
|
89
|
-
const result = await quotationRepo.save({
|
|
90
|
-
...quotation,
|
|
91
|
-
...updateRecord,
|
|
92
|
-
updater: user
|
|
93
|
-
});
|
|
94
|
-
if (updateRecord.thumbnail) {
|
|
95
|
-
await (0, attachment_base_1.deleteAttachmentsByRef)(null, { refBys: [result.id] }, context);
|
|
96
|
-
await (0, attachment_base_1.createAttachment)(null, {
|
|
97
|
-
attachment: {
|
|
98
|
-
file: updateRecord.thumbnail,
|
|
99
|
-
refType: quotation_1.Quotation.name,
|
|
100
|
-
refBy: result.id
|
|
101
|
-
}
|
|
102
|
-
}, context);
|
|
103
|
-
}
|
|
104
|
-
results.push({ ...result, cuFlag: 'M' });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return results;
|
|
19
|
+
sendQuotation(id, context) {
|
|
20
|
+
const { tx, domain, user } = context.state;
|
|
21
|
+
return (0, quotation_service_1.transitionQuotation)(tx, domain, user, id, 'SENT');
|
|
108
22
|
}
|
|
109
|
-
|
|
110
|
-
const { domain,
|
|
111
|
-
|
|
112
|
-
await (0, attachment_base_1.deleteAttachmentsByRef)(null, { refBys: [id] }, context);
|
|
113
|
-
return true;
|
|
23
|
+
acceptQuotation(id, context) {
|
|
24
|
+
const { tx, domain, user } = context.state;
|
|
25
|
+
return (0, quotation_service_1.transitionQuotation)(tx, domain, user, id, 'ACCEPTED');
|
|
114
26
|
}
|
|
115
|
-
|
|
116
|
-
const { domain,
|
|
117
|
-
|
|
118
|
-
domain: { id: domain.id },
|
|
119
|
-
id: (0, typeorm_1.In)(ids)
|
|
120
|
-
});
|
|
121
|
-
await (0, attachment_base_1.deleteAttachmentsByRef)(null, { refBys: ids }, context);
|
|
122
|
-
return true;
|
|
27
|
+
rejectQuotation(id, reason, context) {
|
|
28
|
+
const { tx, domain, user } = context.state;
|
|
29
|
+
return (0, quotation_service_1.transitionQuotation)(tx, domain, user, id, 'REJECTED', reason);
|
|
123
30
|
}
|
|
124
|
-
|
|
125
|
-
const { domain,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
31
|
+
expireQuotation(id, context) {
|
|
32
|
+
const { tx, domain, user } = context.state;
|
|
33
|
+
return (0, quotation_service_1.transitionQuotation)(tx, domain, user, id, 'EXPIRED');
|
|
34
|
+
}
|
|
35
|
+
reviseQuotation(id, context) {
|
|
36
|
+
const { tx, domain, user } = context.state;
|
|
37
|
+
return (0, quotation_service_1.reviseQuotation)(tx, domain, user, id);
|
|
130
38
|
}
|
|
131
39
|
};
|
|
132
40
|
exports.QuotationMutation = QuotationMutation;
|
|
133
41
|
tslib_1.__decorate([
|
|
134
42
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
135
|
-
(0, type_graphql_1.
|
|
43
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "mutation", domainOwnerGranted: true)'),
|
|
44
|
+
(0, type_graphql_1.Mutation)(type => quotation_1.Quotation, { description: 'To create a quotation draft' }),
|
|
136
45
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('quotation')),
|
|
137
46
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
138
47
|
tslib_1.__metadata("design:type", Function),
|
|
139
48
|
tslib_1.__metadata("design:paramtypes", [quotation_type_1.NewQuotation, Object]),
|
|
140
|
-
tslib_1.__metadata("design:returntype",
|
|
49
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
141
50
|
], QuotationMutation.prototype, "createQuotation", null);
|
|
142
51
|
tslib_1.__decorate([
|
|
143
52
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
144
|
-
(0, type_graphql_1.
|
|
53
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "mutation", domainOwnerGranted: true)'),
|
|
54
|
+
(0, type_graphql_1.Mutation)(type => quotation_1.Quotation, { description: 'To replace the head and lines of a quotation draft' }),
|
|
145
55
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
146
|
-
tslib_1.__param(1, (0, type_graphql_1.Arg)('
|
|
56
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('quotation')),
|
|
147
57
|
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
148
58
|
tslib_1.__metadata("design:type", Function),
|
|
149
|
-
tslib_1.__metadata("design:paramtypes", [String, quotation_type_1.
|
|
150
|
-
tslib_1.__metadata("design:returntype",
|
|
59
|
+
tslib_1.__metadata("design:paramtypes", [String, quotation_type_1.NewQuotation, Object]),
|
|
60
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
151
61
|
], QuotationMutation.prototype, "updateQuotation", null);
|
|
152
62
|
tslib_1.__decorate([
|
|
153
63
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
154
|
-
(0, type_graphql_1.
|
|
155
|
-
|
|
64
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "mutation", domainOwnerGranted: true)'),
|
|
65
|
+
(0, type_graphql_1.Mutation)(type => quotation_1.Quotation, { description: 'To send a quotation draft; its amounts are fixed from then on' }),
|
|
66
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
156
67
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
157
68
|
tslib_1.__metadata("design:type", Function),
|
|
158
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
159
|
-
tslib_1.__metadata("design:returntype",
|
|
160
|
-
], QuotationMutation.prototype, "
|
|
69
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
70
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
71
|
+
], QuotationMutation.prototype, "sendQuotation", null);
|
|
161
72
|
tslib_1.__decorate([
|
|
162
73
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
163
|
-
(0, type_graphql_1.
|
|
74
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "mutation", domainOwnerGranted: true)'),
|
|
75
|
+
(0, type_graphql_1.Mutation)(type => quotation_1.Quotation, { description: 'To record that the buyer accepted a sent quotation' }),
|
|
164
76
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
165
77
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
166
78
|
tslib_1.__metadata("design:type", Function),
|
|
167
79
|
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
168
|
-
tslib_1.__metadata("design:returntype",
|
|
169
|
-
], QuotationMutation.prototype, "
|
|
80
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
81
|
+
], QuotationMutation.prototype, "acceptQuotation", null);
|
|
82
|
+
tslib_1.__decorate([
|
|
83
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
84
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "mutation", domainOwnerGranted: true)'),
|
|
85
|
+
(0, type_graphql_1.Mutation)(type => quotation_1.Quotation, { description: 'To record that the buyer declined a sent quotation, with the reason' }),
|
|
86
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
87
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('reason')),
|
|
88
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
89
|
+
tslib_1.__metadata("design:type", Function),
|
|
90
|
+
tslib_1.__metadata("design:paramtypes", [String, String, Object]),
|
|
91
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
92
|
+
], QuotationMutation.prototype, "rejectQuotation", null);
|
|
170
93
|
tslib_1.__decorate([
|
|
171
94
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
172
|
-
(0, type_graphql_1.
|
|
173
|
-
|
|
95
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "mutation", domainOwnerGranted: true)'),
|
|
96
|
+
(0, type_graphql_1.Mutation)(type => quotation_1.Quotation, { description: 'To close a sent quotation whose last day has passed' }),
|
|
97
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
174
98
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
175
99
|
tslib_1.__metadata("design:type", Function),
|
|
176
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
177
|
-
tslib_1.__metadata("design:returntype",
|
|
178
|
-
], QuotationMutation.prototype, "
|
|
100
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
101
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
102
|
+
], QuotationMutation.prototype, "expireQuotation", null);
|
|
179
103
|
tslib_1.__decorate([
|
|
180
104
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
181
|
-
(0, type_graphql_1.
|
|
182
|
-
|
|
105
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "mutation", domainOwnerGranted: true)'),
|
|
106
|
+
(0, type_graphql_1.Mutation)(type => quotation_1.Quotation, { description: 'To start the next version of a sent quotation, keeping its number' }),
|
|
107
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
183
108
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
184
109
|
tslib_1.__metadata("design:type", Function),
|
|
185
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
186
|
-
tslib_1.__metadata("design:returntype",
|
|
187
|
-
], QuotationMutation.prototype, "
|
|
110
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
111
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
112
|
+
], QuotationMutation.prototype, "reviseQuotation", null);
|
|
188
113
|
exports.QuotationMutation = QuotationMutation = tslib_1.__decorate([
|
|
114
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
|
|
189
115
|
(0, type_graphql_1.Resolver)(quotation_1.Quotation)
|
|
190
116
|
], QuotationMutation);
|
|
191
117
|
//# sourceMappingURL=quotation-mutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotation-mutation.js","sourceRoot":"","sources":["../../../server/service/quotation/quotation-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,qEAA0F;AAE1F,2CAAuC;AACvC,qDAA+D;AAGxD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAGtB,AAAN,KAAK,CAAC,eAAe,CAAmB,SAAuB,EAAS,OAAwB;QAC9F,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,qBAAS,CAAC,CAAC,IAAI,CAAC;YACpD,GAAG,SAAS;YACZ,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QAEF,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;YACxB,MAAM,IAAA,kCAAgB,EACpB,IAAI,EACJ;gBACE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,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IAE5E,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;yDAYP;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;IAE5E,mBAAA,IAAA,kBAAG,EAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,+BAAc,CAAC,CAAC,CAAA;IAC3C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;yDAWP;4BAjMU,iBAAiB;IAD7B,IAAA,uBAAQ,EAAC,qBAAS,CAAC;GACP,iBAAiB,CAkM7B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\n\nimport { Quotation } from './quotation'\nimport { NewQuotation, QuotationPatch } from './quotation-type'\n\n@Resolver(Quotation)\nexport class QuotationMutation {\n @Directive('@transaction')\n @Mutation(returns => Quotation, { description: 'To create new Quotation' })\n async createQuotation(@Arg('quotation') quotation: NewQuotation, @Ctx() context: ResolverContext): Promise<Quotation> {\n const { domain, user, tx } = context.state\n\n const result = await tx.getRepository(Quotation).save({\n ...quotation,\n domain,\n creator: user,\n updater: user\n })\n\n if (quotation.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: quotation.thumbnail,\n refType: Quotation.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => Quotation, { description: 'To modify Quotation information' })\n async updateQuotation(\n @Arg('id') id: string,\n @Arg('patch') patch: QuotationPatch,\n @Ctx() context: ResolverContext\n ): Promise<Quotation> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(Quotation)\n const quotation = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...quotation,\n ...patch,\n updater: user\n })\n\n if (patch.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.thumbnail,\n refType: Quotation.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => [Quotation], { description: \"To modify multiple Quotations' information\" })\n async updateMultipleQuotation(\n @Arg('patches', type => [QuotationPatch]) patches: QuotationPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Quotation[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const quotationRepo = tx.getRepository(Quotation)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await quotationRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n if (newRecord.thumbnail) {\n await createAttachment(\n null,\n {\n attachment: {\n file: newRecord.thumbnail,\n refType: Quotation.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const quotation = await quotationRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!quotation) {\n throw new Error(`failed to find quotation to update: ${updateRecord.id}`)\n }\n\n const result = await quotationRepo.save({\n ...quotation,\n ...updateRecord,\n updater: user\n })\n\n if (updateRecord.thumbnail) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: updateRecord.thumbnail,\n refType: Quotation.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete Quotation' })\n async deleteQuotation(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Quotation).delete({ domain: { id: domain.id }, id })\n await deleteAttachmentsByRef(null, { refBys: [id] }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple Quotations' })\n async deleteQuotations(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(Quotation).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n await deleteAttachmentsByRef(null, { refBys: ids }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To import multiple Quotations' })\n async importQuotations(\n @Arg('quotations', type => [QuotationPatch]) quotations: QuotationPatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n quotations.map(async (quotation: QuotationPatch) => {\n const createdQuotation: Quotation = await tx.getRepository(Quotation).save({ domain, ...quotation })\n })\n )\n\n return true\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"quotation-mutation.js","sourceRoot":"","sources":["../../../server/service/quotation/quotation-mutation.ts"],"names":[],"mappings":";;;;AAAA,iDAAqD;AACrD,+CAAqF;AAErF,2CAAuC;AACvC,2DAAyF;AACzF,qDAA+C;AAIxC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAI5B,eAAe,CAAmB,SAAuB,EAAS,OAAwB;QACxF,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,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vDU,iBAAiB;IAF7B,IAAA,4BAAa,EAAC,qBAAa,CAAC;IAC5B,IAAA,uBAAQ,EAAC,qBAAS,CAAC;GACP,iBAAiB,CAwD7B","sourcesContent":["import { SpeakRefusals } from '@things-factory/shell'\nimport { Arg, Ctx, Directive, Mutation, Resolver, UseMiddleware } from 'type-graphql'\n\nimport { Quotation } from './quotation'\nimport { reviseQuotation, saveQuotation, transitionQuotation } from './quotation-service'\nimport { NewQuotation } from './quotation-type'\n\n@UseMiddleware(SpeakRefusals)\n@Resolver(Quotation)\nexport class QuotationMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"quotation\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Quotation, { description: 'To create a quotation draft' })\n createQuotation(@Arg('quotation') quotation: NewQuotation, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveQuotation(tx, domain, user, quotation)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"quotation\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Quotation, { description: 'To replace the head and lines of a quotation draft' })\n updateQuotation(@Arg('id') id: string, @Arg('quotation') quotation: NewQuotation, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveQuotation(tx, domain, user, quotation, id)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"quotation\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Quotation, { description: 'To send a quotation draft; its amounts are fixed from then on' })\n sendQuotation(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return transitionQuotation(tx, domain, user, id, 'SENT')\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"quotation\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Quotation, { description: 'To record that the buyer accepted a sent quotation' })\n acceptQuotation(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return transitionQuotation(tx, domain, user, id, 'ACCEPTED')\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"quotation\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Quotation, { description: 'To record that the buyer declined a sent quotation, with the reason' })\n rejectQuotation(@Arg('id') id: string, @Arg('reason') reason: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return transitionQuotation(tx, domain, user, id, 'REJECTED', reason)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"quotation\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Quotation, { description: 'To close a sent quotation whose last day has passed' })\n expireQuotation(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return transitionQuotation(tx, domain, user, id, 'EXPIRED')\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"quotation\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Quotation, { description: 'To start the next version of a sent quotation, keeping its number' })\n reviseQuotation(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return reviseQuotation(tx, domain, user, id)\n }\n}\n"]}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { Domain, ListParam } from '@things-factory/shell';
|
|
2
1
|
import { User } from '@things-factory/auth-base';
|
|
2
|
+
import { Domain, ListParam } from '@things-factory/shell';
|
|
3
3
|
import { Quotation } from './quotation';
|
|
4
|
+
import { QuotationEvent } from './quotation-event';
|
|
5
|
+
import { QuotationItem } from './quotation-item';
|
|
4
6
|
import { QuotationList } from './quotation-type';
|
|
5
7
|
export declare class QuotationQuery {
|
|
6
8
|
quotation(id: string, context: ResolverContext): Promise<Quotation>;
|
|
7
9
|
quotations(params: ListParam, context: ResolverContext): Promise<QuotationList>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
quotationVersions(number: string, context: ResolverContext): Promise<Quotation[]>;
|
|
11
|
+
quotationEvents(quotationId: string, context: ResolverContext): Promise<QuotationEvent[]>;
|
|
12
|
+
items(quotation: Quotation): Promise<QuotationItem[]>;
|
|
13
|
+
taxGroups(quotation: Quotation): Promise<import("@things-factory/invoice").TaxGroup[]>;
|
|
14
|
+
domain(row: Quotation): Domain | Promise<Domain>;
|
|
15
|
+
creator(row: Quotation): User | Promise<User>;
|
|
16
|
+
updater(row: Quotation): User | Promise<User>;
|
|
12
17
|
}
|
|
@@ -2,61 +2,63 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuotationQuery = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const type_graphql_1 = require("type-graphql");
|
|
6
|
-
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
7
|
-
const shell_1 = require("@things-factory/shell");
|
|
8
5
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
|
+
const invoice_1 = require("@things-factory/invoice");
|
|
7
|
+
const shell_1 = require("@things-factory/shell");
|
|
8
|
+
const type_graphql_1 = require("type-graphql");
|
|
9
9
|
const quotation_1 = require("./quotation");
|
|
10
|
+
const quotation_event_1 = require("./quotation-event");
|
|
11
|
+
const quotation_item_1 = require("./quotation-item");
|
|
10
12
|
const quotation_type_1 = require("./quotation-type");
|
|
11
13
|
let QuotationQuery = class QuotationQuery {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return await (0, shell_1.getRepository)(quotation_1.Quotation).findOne({
|
|
15
|
-
where: { domain: { id: domain.id }, id }
|
|
16
|
-
});
|
|
14
|
+
quotation(id, context) {
|
|
15
|
+
return (0, shell_1.getRepository)(quotation_1.Quotation).findOne({ where: { id, domain: { id: context.state.domain.id } } });
|
|
17
16
|
}
|
|
18
17
|
async quotations(params, context) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
domain,
|
|
18
|
+
const query = (0, shell_1.getQueryBuilderFromListParams)({
|
|
19
|
+
domain: context.state.domain,
|
|
22
20
|
params,
|
|
23
|
-
repository:
|
|
24
|
-
searchables: ['
|
|
21
|
+
repository: (0, shell_1.getRepository)(quotation_1.Quotation),
|
|
22
|
+
searchables: ['number', 'supplierName', 'buyerName', 'notes']
|
|
25
23
|
});
|
|
26
|
-
const [items, total] = await
|
|
24
|
+
const [items, total] = await query.getManyAndCount();
|
|
27
25
|
return { items, total };
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
refBy: quotation.id
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return attachment?.fullpath;
|
|
27
|
+
quotationVersions(number, context) {
|
|
28
|
+
return (0, shell_1.getRepository)(quotation_1.Quotation).find({ where: { domain: { id: context.state.domain.id }, number }, order: { version: 'ASC' } });
|
|
29
|
+
}
|
|
30
|
+
quotationEvents(quotationId, context) {
|
|
31
|
+
return (0, shell_1.getRepository)(quotation_event_1.QuotationEvent).find({ where: { domain: { id: context.state.domain.id }, quotation: { id: quotationId } }, order: { createdAt: 'ASC' } });
|
|
38
32
|
}
|
|
39
|
-
async
|
|
40
|
-
return
|
|
33
|
+
async items(quotation) {
|
|
34
|
+
return quotation.items ?? (0, shell_1.getRepository)(quotation_item_1.QuotationItem).find({ where: { quotation: { id: quotation.id } }, order: { position: 'ASC' } });
|
|
41
35
|
}
|
|
42
|
-
async
|
|
43
|
-
return
|
|
36
|
+
async taxGroups(quotation) {
|
|
37
|
+
return (0, invoice_1.taxGroupsOf)({ ...quotation, items: await this.items(quotation) });
|
|
44
38
|
}
|
|
45
|
-
|
|
46
|
-
return
|
|
39
|
+
domain(row) {
|
|
40
|
+
return row.domain ?? (row.domainId ? (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: row.domainId }) : undefined);
|
|
41
|
+
}
|
|
42
|
+
creator(row) {
|
|
43
|
+
return row.creator ?? (row.creatorId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.creatorId }) : undefined);
|
|
44
|
+
}
|
|
45
|
+
updater(row) {
|
|
46
|
+
return row.updater ?? (row.updaterId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.updaterId }) : undefined);
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
exports.QuotationQuery = QuotationQuery;
|
|
50
50
|
tslib_1.__decorate([
|
|
51
|
-
(0, type_graphql_1.
|
|
51
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "query", domainOwnerGranted: true)'),
|
|
52
|
+
(0, type_graphql_1.Query)(type => quotation_1.Quotation, { nullable: true, description: 'To fetch a quotation' }),
|
|
52
53
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
53
54
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
54
55
|
tslib_1.__metadata("design:type", Function),
|
|
55
56
|
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
56
|
-
tslib_1.__metadata("design:returntype",
|
|
57
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
57
58
|
], QuotationQuery.prototype, "quotation", null);
|
|
58
59
|
tslib_1.__decorate([
|
|
59
|
-
(0, type_graphql_1.
|
|
60
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "query", domainOwnerGranted: true)'),
|
|
61
|
+
(0, type_graphql_1.Query)(type => quotation_type_1.QuotationList, { description: 'To fetch a page of quotations' }),
|
|
60
62
|
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
|
61
63
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
62
64
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -64,34 +66,60 @@ tslib_1.__decorate([
|
|
|
64
66
|
tslib_1.__metadata("design:returntype", Promise)
|
|
65
67
|
], QuotationQuery.prototype, "quotations", null);
|
|
66
68
|
tslib_1.__decorate([
|
|
67
|
-
(0, type_graphql_1.
|
|
69
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "query", domainOwnerGranted: true)'),
|
|
70
|
+
(0, type_graphql_1.Query)(type => [quotation_1.Quotation], { description: 'To fetch every version of a quotation number, oldest first' }),
|
|
71
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('number')),
|
|
72
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
73
|
+
tslib_1.__metadata("design:type", Function),
|
|
74
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
75
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
76
|
+
], QuotationQuery.prototype, "quotationVersions", null);
|
|
77
|
+
tslib_1.__decorate([
|
|
78
|
+
(0, type_graphql_1.Directive)('@privilege(category: "quotation", privilege: "query", domainOwnerGranted: true)'),
|
|
79
|
+
(0, type_graphql_1.Query)(type => [quotation_event_1.QuotationEvent], { description: 'To fetch what happened to a quotation, oldest first' }),
|
|
80
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('quotationId')),
|
|
81
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
82
|
+
tslib_1.__metadata("design:type", Function),
|
|
83
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
84
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
85
|
+
], QuotationQuery.prototype, "quotationEvents", null);
|
|
86
|
+
tslib_1.__decorate([
|
|
87
|
+
(0, type_graphql_1.FieldResolver)(type => [quotation_item_1.QuotationItem]),
|
|
68
88
|
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
69
89
|
tslib_1.__metadata("design:type", Function),
|
|
70
90
|
tslib_1.__metadata("design:paramtypes", [quotation_1.Quotation]),
|
|
71
91
|
tslib_1.__metadata("design:returntype", Promise)
|
|
72
|
-
], QuotationQuery.prototype, "
|
|
92
|
+
], QuotationQuery.prototype, "items", null);
|
|
73
93
|
tslib_1.__decorate([
|
|
74
|
-
(0, type_graphql_1.FieldResolver)(type =>
|
|
94
|
+
(0, type_graphql_1.FieldResolver)(type => [invoice_1.DocumentTaxGroup]),
|
|
75
95
|
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
76
96
|
tslib_1.__metadata("design:type", Function),
|
|
77
97
|
tslib_1.__metadata("design:paramtypes", [quotation_1.Quotation]),
|
|
78
98
|
tslib_1.__metadata("design:returntype", Promise)
|
|
79
|
-
], QuotationQuery.prototype, "
|
|
99
|
+
], QuotationQuery.prototype, "taxGroups", null);
|
|
80
100
|
tslib_1.__decorate([
|
|
81
|
-
(0, type_graphql_1.FieldResolver)(type =>
|
|
101
|
+
(0, type_graphql_1.FieldResolver)(type => shell_1.Domain, { nullable: true }),
|
|
82
102
|
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
83
103
|
tslib_1.__metadata("design:type", Function),
|
|
84
104
|
tslib_1.__metadata("design:paramtypes", [quotation_1.Quotation]),
|
|
85
|
-
tslib_1.__metadata("design:returntype",
|
|
86
|
-
], QuotationQuery.prototype, "
|
|
105
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
106
|
+
], QuotationQuery.prototype, "domain", null);
|
|
87
107
|
tslib_1.__decorate([
|
|
88
|
-
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User),
|
|
108
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
89
109
|
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
90
110
|
tslib_1.__metadata("design:type", Function),
|
|
91
111
|
tslib_1.__metadata("design:paramtypes", [quotation_1.Quotation]),
|
|
92
|
-
tslib_1.__metadata("design:returntype",
|
|
112
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
93
113
|
], QuotationQuery.prototype, "creator", null);
|
|
114
|
+
tslib_1.__decorate([
|
|
115
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
116
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
117
|
+
tslib_1.__metadata("design:type", Function),
|
|
118
|
+
tslib_1.__metadata("design:paramtypes", [quotation_1.Quotation]),
|
|
119
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
120
|
+
], QuotationQuery.prototype, "updater", null);
|
|
94
121
|
exports.QuotationQuery = QuotationQuery = tslib_1.__decorate([
|
|
122
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
|
|
95
123
|
(0, type_graphql_1.Resolver)(quotation_1.Quotation)
|
|
96
124
|
], QuotationQuery);
|
|
97
125
|
//# sourceMappingURL=quotation-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotation-query.js","sourceRoot":"","sources":["../../../server/service/quotation/quotation-query.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"quotation-query.js","sourceRoot":"","sources":["../../../server/service/quotation/quotation-query.ts"],"names":[],"mappings":";;;;AAAA,yDAAgD;AAChD,qDAAuE;AACvE,iDAAsH;AACtH,+CAA6G;AAE7G,2CAAuC;AACvC,uDAAkD;AAClD,qDAAgD;AAChD,qDAAgD;AAIzC,IAAM,cAAc,GAApB,MAAM,cAAc;IAGzB,SAAS,CAAY,EAAU,EAAS,OAAwB;QAC9D,OAAO,IAAA,qBAAa,EAAC,qBAAS,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IACrG,CAAC;IAIK,AAAN,KAAK,CAAC,UAAU,CAA0B,MAAiB,EAAS,OAAwB;QAC1F,MAAM,KAAK,GAAG,IAAA,qCAA6B,EAAC;YAC1C,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;YAC5B,MAAM;YACN,UAAU,EAAE,IAAA,qBAAa,EAAC,qBAAS,CAAC;YACpC,WAAW,EAAE,CAAC,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,CAAC;SAC9D,CAAC,CAAA;QACF,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,KA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7B;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACvC,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAM,qBAAS;;6CAE7B;yBAvDU,cAAc;IAF1B,IAAA,4BAAa,EAAC,qBAAa,CAAC;IAC5B,IAAA,uBAAQ,EAAC,qBAAS,CAAC;GACP,cAAc,CAwD1B","sourcesContent":["import { User } from '@things-factory/auth-base'\nimport { DocumentTaxGroup, taxGroupsOf } from '@things-factory/invoice'\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam, SpeakRefusals } from '@things-factory/shell'\nimport { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root, UseMiddleware } from 'type-graphql'\n\nimport { Quotation } from './quotation'\nimport { QuotationEvent } from './quotation-event'\nimport { QuotationItem } from './quotation-item'\nimport { QuotationList } from './quotation-type'\n\n@UseMiddleware(SpeakRefusals)\n@Resolver(Quotation)\nexport class QuotationQuery {\n @Directive('@privilege(category: \"quotation\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => Quotation, { nullable: true, description: 'To fetch a quotation' })\n quotation(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n return getRepository(Quotation).findOne({ where: { id, domain: { id: context.state.domain.id } } })\n }\n\n @Directive('@privilege(category: \"quotation\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => QuotationList, { description: 'To fetch a page of quotations' })\n async quotations(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<QuotationList> {\n const query = getQueryBuilderFromListParams({\n domain: context.state.domain,\n params,\n repository: getRepository(Quotation),\n searchables: ['number', 'supplierName', 'buyerName', 'notes']\n })\n const [items, total] = await query.getManyAndCount()\n return { items, total }\n }\n\n @Directive('@privilege(category: \"quotation\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => [Quotation], { description: 'To fetch every version of a quotation number, oldest first' })\n quotationVersions(@Arg('number') number: string, @Ctx() context: ResolverContext) {\n return getRepository(Quotation).find({ where: { domain: { id: context.state.domain.id }, number }, order: { version: 'ASC' } })\n }\n\n @Directive('@privilege(category: \"quotation\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => [QuotationEvent], { description: 'To fetch what happened to a quotation, oldest first' })\n quotationEvents(@Arg('quotationId') quotationId: string, @Ctx() context: ResolverContext) {\n return getRepository(QuotationEvent).find({ where: { domain: { id: context.state.domain.id }, quotation: { id: quotationId } }, order: { createdAt: 'ASC' } })\n }\n\n @FieldResolver(type => [QuotationItem])\n async items(@Root() quotation: Quotation) {\n return quotation.items ?? getRepository(QuotationItem).find({ where: { quotation: { id: quotation.id } }, order: { position: 'ASC' } })\n }\n\n @FieldResolver(type => [DocumentTaxGroup])\n async taxGroups(@Root() quotation: Quotation) {\n return taxGroupsOf({ ...quotation, items: await this.items(quotation) })\n }\n\n @FieldResolver(type => Domain, { nullable: true })\n domain(@Root() row: Quotation) {\n return row.domain ?? (row.domainId ? getRepository(Domain).findOneBy({ id: row.domainId }) : undefined)\n }\n\n @FieldResolver(type => User, { nullable: true })\n creator(@Root() row: Quotation) {\n return row.creator ?? (row.creatorId ? getRepository(User).findOneBy({ id: row.creatorId }) : undefined)\n }\n\n @FieldResolver(type => User, { nullable: true })\n updater(@Root() row: Quotation) {\n return row.updater ?? (row.updaterId ? getRepository(User).findOneBy({ id: row.updaterId }) : undefined)\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QuotationStatus } from './quotation';
|
|
2
|
+
export type QuotationAction = 'SENT' | 'ACCEPTED' | 'REJECTED' | 'EXPIRED';
|
|
3
|
+
/** The status an action leads to from where the quotation stands on `today`, or undefined when it may not. */
|
|
4
|
+
export declare function quotationTransition(status: string, action: QuotationAction, validUntil: string, today: string): QuotationStatus | undefined;
|
|
5
|
+
/** Only the latest sent version that nobody accepted may be revised. */
|
|
6
|
+
export declare function revisable(status: string): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quotationTransition = quotationTransition;
|
|
4
|
+
exports.revisable = revisable;
|
|
5
|
+
const quotation_1 = require("./quotation");
|
|
6
|
+
/** The status an action leads to from where the quotation stands on `today`, or undefined when it may not. */
|
|
7
|
+
function quotationTransition(status, action, validUntil, today) {
|
|
8
|
+
if (action === 'SENT' && status === quotation_1.QuotationStatus.DRAFT && validUntil >= today)
|
|
9
|
+
return quotation_1.QuotationStatus.SENT;
|
|
10
|
+
if (action === 'ACCEPTED' && status === quotation_1.QuotationStatus.SENT && validUntil >= today)
|
|
11
|
+
return quotation_1.QuotationStatus.ACCEPTED;
|
|
12
|
+
if (action === 'REJECTED' && status === quotation_1.QuotationStatus.SENT)
|
|
13
|
+
return quotation_1.QuotationStatus.REJECTED;
|
|
14
|
+
if (action === 'EXPIRED' && status === quotation_1.QuotationStatus.SENT && validUntil < today)
|
|
15
|
+
return quotation_1.QuotationStatus.EXPIRED;
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Only the latest sent version that nobody accepted may be revised. */
|
|
19
|
+
function revisable(status) {
|
|
20
|
+
return [quotation_1.QuotationStatus.SENT, quotation_1.QuotationStatus.REJECTED, quotation_1.QuotationStatus.EXPIRED].includes(status);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=quotation-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotation-rules.js","sourceRoot":"","sources":["../../../server/service/quotation/quotation-rules.ts"],"names":[],"mappings":";;AAKA,kDAMC;AAGD,8BAEC;AAhBD,2CAA6C;AAI7C,8GAA8G;AAC9G,SAAgB,mBAAmB,CAAC,MAAc,EAAE,MAAuB,EAAE,UAAkB,EAAE,KAAa;IAC5G,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,2BAAe,CAAC,KAAK,IAAI,UAAU,IAAI,KAAK;QAAE,OAAO,2BAAe,CAAC,IAAI,CAAA;IAC7G,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,2BAAe,CAAC,IAAI,IAAI,UAAU,IAAI,KAAK;QAAE,OAAO,2BAAe,CAAC,QAAQ,CAAA;IACpH,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,2BAAe,CAAC,IAAI;QAAE,OAAO,2BAAe,CAAC,QAAQ,CAAA;IAC7F,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,2BAAe,CAAC,IAAI,IAAI,UAAU,GAAG,KAAK;QAAE,OAAO,2BAAe,CAAC,OAAO,CAAA;IACjH,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,wEAAwE;AACxE,SAAgB,SAAS,CAAC,MAAc;IACtC,OAAO,CAAC,2BAAe,CAAC,IAAI,EAAE,2BAAe,CAAC,QAAQ,EAAE,2BAAe,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAyB,CAAC,CAAA;AACtH,CAAC","sourcesContent":["import { QuotationStatus } from './quotation'\n\nexport type QuotationAction = 'SENT' | 'ACCEPTED' | 'REJECTED' | 'EXPIRED'\n\n/** The status an action leads to from where the quotation stands on `today`, or undefined when it may not. */\nexport function quotationTransition(status: string, action: QuotationAction, validUntil: string, today: string): QuotationStatus | undefined {\n if (action === 'SENT' && status === QuotationStatus.DRAFT && validUntil >= today) return QuotationStatus.SENT\n if (action === 'ACCEPTED' && status === QuotationStatus.SENT && validUntil >= today) return QuotationStatus.ACCEPTED\n if (action === 'REJECTED' && status === QuotationStatus.SENT) return QuotationStatus.REJECTED\n if (action === 'EXPIRED' && status === QuotationStatus.SENT && validUntil < today) return QuotationStatus.EXPIRED\n return undefined\n}\n\n/** Only the latest sent version that nobody accepted may be revised. */\nexport function revisable(status: string): boolean {\n return [QuotationStatus.SENT, QuotationStatus.REJECTED, QuotationStatus.EXPIRED].includes(status as QuotationStatus)\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Domain } from '@things-factory/shell';
|
|
2
|
+
import { EntityManager } from 'typeorm';
|
|
3
|
+
import { Quotation } from './quotation';
|
|
4
|
+
import { QuotationAction } from './quotation-rules';
|
|
5
|
+
import { NewQuotation } from './quotation-type';
|
|
6
|
+
export declare function quotationInDomain(tx: EntityManager, domain: Domain, id: string): Promise<Quotation>;
|
|
7
|
+
export declare function saveQuotation(tx: EntityManager, domain: Domain, user: any, input: NewQuotation, id?: string): Promise<Quotation>;
|
|
8
|
+
export declare function transitionQuotation(tx: EntityManager, domain: Domain, user: any, id: string, action: QuotationAction, reason?: string): Promise<Quotation>;
|
|
9
|
+
/** A new draft version of a sent quotation, with the same number; the version it replaces is superseded. */
|
|
10
|
+
export declare function reviseQuotation(tx: EntityManager, domain: Domain, user: any, id: string): Promise<Quotation>;
|
|
11
|
+
/** The quotation as printed. */
|
|
12
|
+
export declare function snapshotOf(quotation: Quotation): {
|
|
13
|
+
items: {
|
|
14
|
+
position: number;
|
|
15
|
+
description: string;
|
|
16
|
+
quantity: number;
|
|
17
|
+
unitPrice: number;
|
|
18
|
+
discount: number;
|
|
19
|
+
taxKind: import("@things-factory/invoice").TaxKind;
|
|
20
|
+
taxRate: number;
|
|
21
|
+
supplyAmount: number;
|
|
22
|
+
}[];
|
|
23
|
+
};
|