@things-factory/sales 0.0.0-stage → 10.1.177
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 +8 -0
- package/assets/images/hatiolab-logo.png +0 -0
- package/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +5 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/entity360/opportunity-360.d.ts +12 -0
- package/dist-client/entity360/opportunity-360.js +114 -0
- package/dist-client/entity360/opportunity-360.js.map +1 -0
- package/dist-client/index.d.ts +4 -0
- package/dist-client/index.js +5 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/opportunity-attach.d.ts +17 -0
- package/dist-client/opportunity-attach.js +8 -0
- package/dist-client/opportunity-attach.js.map +1 -0
- package/dist-client/opportunity-words.d.ts +1 -0
- package/dist-client/opportunity-words.js +13 -0
- package/dist-client/opportunity-words.js.map +1 -0
- package/dist-client/pages/opportunity-editor.d.ts +83 -0
- package/dist-client/pages/opportunity-editor.js +528 -0
- package/dist-client/pages/opportunity-editor.js.map +1 -0
- package/dist-client/pages/opportunity-list.d.ts +40 -0
- package/dist-client/pages/opportunity-list.js +134 -0
- package/dist-client/pages/opportunity-list.js.map +1 -0
- package/dist-client/pages/quotation-editor.d.ts +54 -0
- package/dist-client/pages/quotation-editor.js +359 -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 -0
- package/dist-client/route.js +17 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/controllers/index.d.ts +0 -0
- package/dist-server/controllers/index.js +1 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/index.d.ts +4 -0
- package/dist-server/index.js +8 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/middlewares/index.d.ts +2 -0
- package/dist-server/middlewares/index.js +7 -0
- package/dist-server/middlewares/index.js.map +1 -0
- package/dist-server/migrations/index.d.ts +1 -0
- package/dist-server/migrations/index.js +12 -0
- package/dist-server/migrations/index.js.map +1 -0
- package/dist-server/routes.d.ts +0 -0
- package/dist-server/routes.js +24 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/index.d.ts +16 -0
- package/dist-server/service/index.js +21 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/opportunity/index.d.ts +8 -0
- package/dist-server/service/opportunity/index.js +12 -0
- package/dist-server/service/opportunity/index.js.map +1 -0
- package/dist-server/service/opportunity/opportunity-event-query.d.ts +9 -0
- package/dist-server/service/opportunity/opportunity-event-query.js +55 -0
- package/dist-server/service/opportunity/opportunity-event-query.js.map +1 -0
- package/dist-server/service/opportunity/opportunity-event.d.ts +27 -0
- package/dist-server/service/opportunity/opportunity-event.js +115 -0
- package/dist-server/service/opportunity/opportunity-event.js.map +1 -0
- package/dist-server/service/opportunity/opportunity-mutation.d.ts +7 -0
- package/dist-server/service/opportunity/opportunity-mutation.js +64 -0
- package/dist-server/service/opportunity/opportunity-mutation.js.map +1 -0
- package/dist-server/service/opportunity/opportunity-query.d.ts +21 -0
- package/dist-server/service/opportunity/opportunity-query.js +156 -0
- package/dist-server/service/opportunity/opportunity-query.js.map +1 -0
- package/dist-server/service/opportunity/opportunity-rules.d.ts +22 -0
- package/dist-server/service/opportunity/opportunity-rules.js +59 -0
- package/dist-server/service/opportunity/opportunity-rules.js.map +1 -0
- package/dist-server/service/opportunity/opportunity-service.d.ts +19 -0
- package/dist-server/service/opportunity/opportunity-service.js +107 -0
- package/dist-server/service/opportunity/opportunity-service.js.map +1 -0
- package/dist-server/service/opportunity/opportunity-type.d.ts +23 -0
- package/dist-server/service/opportunity/opportunity-type.js +86 -0
- package/dist-server/service/opportunity/opportunity-type.js.map +1 -0
- package/dist-server/service/opportunity/opportunity.d.ts +35 -0
- package/dist-server/service/opportunity/opportunity.js +147 -0
- package/dist-server/service/opportunity/opportunity.js.map +1 -0
- package/dist-server/service/quotation/index.d.ts +10 -0
- package/dist-server/service/quotation/index.js +14 -0
- package/dist-server/service/quotation/index.js.map +1 -0
- 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 +11 -0
- package/dist-server/service/quotation/quotation-mutation.js +117 -0
- package/dist-server/service/quotation/quotation-mutation.js.map +1 -0
- package/dist-server/service/quotation/quotation-query.d.ts +19 -0
- package/dist-server/service/quotation/quotation-query.js +136 -0
- package/dist-server/service/quotation/quotation-query.js.map +1 -0
- 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 +25 -0
- package/dist-server/service/quotation/quotation-service.js +127 -0
- package/dist-server/service/quotation/quotation-service.js.map +1 -0
- package/dist-server/service/quotation/quotation-type.d.ts +10 -0
- package/dist-server/service/quotation/quotation-type.js +36 -0
- package/dist-server/service/quotation/quotation-type.js.map +1 -0
- package/dist-server/service/quotation/quotation.d.ts +36 -0
- package/dist-server/service/quotation/quotation.js +121 -0
- package/dist-server/service/quotation/quotation.js.map +1 -0
- package/dist-server/service/sales-event.d.ts +15 -0
- package/dist-server/service/sales-event.js +12 -0
- package/dist-server/service/sales-event.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/helps/quotation/quotation.md +160 -0
- package/package.json +46 -4
- package/things-factory.config.js +13 -0
- package/translations/en.json +102 -0
- package/translations/es.json +102 -0
- package/translations/ja.json +102 -0
- package/translations/ko.json +102 -0
- package/translations/ms.json +102 -0
- package/translations/zh.json +102 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,gEAAqC;AACrC,qEAA0C;AAC1C,sEAA2C;AAC3C,sEAA2C;AAC3C,wEAA6C;AAC7C,qEAA0C;AAC1C,oEAAyC;AACzC,0EAA+C;AAC/C,0EAA+C;AAC/C,4EAAiD;AACjD,yEAA8C;AAE9C,mEAA4C;AAC5C,+DAAwC;AAE3B,QAAA,QAAQ,GAAG,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;AAC3D,QAAA,WAAW,GAAG,CAAC,GAAG,SAAS,CAAC,WAAW,EAAE,GAAG,WAAW,CAAC,WAAW,CAAC,CAAA;AACpE,QAAA,MAAM,GAAG,EAAE,eAAe,EAAE,CAAC,GAAG,SAAS,CAAC,SAAS,EAAE,GAAG,WAAW,CAAC,SAAS,CAAC,EAAE,CAAA","sourcesContent":["export * from './quotation/quotation'\nexport * from './quotation/quotation-item'\nexport * from './quotation/quotation-event'\nexport * from './quotation/quotation-rules'\nexport * from './quotation/quotation-service'\nexport * from './quotation/quotation-type'\nexport * from './opportunity/opportunity'\nexport * from './opportunity/opportunity-event'\nexport * from './opportunity/opportunity-rules'\nexport * from './opportunity/opportunity-service'\nexport * from './opportunity/opportunity-type'\n\nimport * as opportunity from './opportunity'\nimport * as quotation from './quotation'\n\nexport const entities = [...quotation.entities, ...opportunity.entities]\nexport const subscribers = [...quotation.subscribers, ...opportunity.subscribers]\nexport const schema = { resolverClasses: [...quotation.resolvers, ...opportunity.resolvers] }\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Opportunity } from './opportunity';
|
|
2
|
+
import { OpportunityEvent } from './opportunity-event';
|
|
3
|
+
import { OpportunityEventQuery } from './opportunity-event-query';
|
|
4
|
+
import { OpportunityMutation } from './opportunity-mutation';
|
|
5
|
+
import { OpportunityQuery } from './opportunity-query';
|
|
6
|
+
export declare const entities: (typeof Opportunity | typeof OpportunityEvent)[];
|
|
7
|
+
export declare const resolvers: (typeof OpportunityQuery | typeof OpportunityMutation | typeof OpportunityEventQuery)[];
|
|
8
|
+
export declare const subscribers: any[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribers = exports.resolvers = exports.entities = void 0;
|
|
4
|
+
const opportunity_1 = require("./opportunity");
|
|
5
|
+
const opportunity_event_1 = require("./opportunity-event");
|
|
6
|
+
const opportunity_event_query_1 = require("./opportunity-event-query");
|
|
7
|
+
const opportunity_mutation_1 = require("./opportunity-mutation");
|
|
8
|
+
const opportunity_query_1 = require("./opportunity-query");
|
|
9
|
+
exports.entities = [opportunity_1.Opportunity, opportunity_event_1.OpportunityEvent];
|
|
10
|
+
exports.resolvers = [opportunity_query_1.OpportunityQuery, opportunity_mutation_1.OpportunityMutation, opportunity_event_query_1.OpportunityEventQuery];
|
|
11
|
+
exports.subscribers = [];
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/opportunity/index.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAC3C,2DAAsD;AACtD,uEAAiE;AACjE,iEAA4D;AAC5D,2DAAsD;AAEzC,QAAA,QAAQ,GAAG,CAAC,yBAAW,EAAE,oCAAgB,CAAC,CAAA;AAC1C,QAAA,SAAS,GAAG,CAAC,oCAAgB,EAAE,0CAAmB,EAAE,+CAAqB,CAAC,CAAA;AAC1E,QAAA,WAAW,GAAG,EAAE,CAAA","sourcesContent":["import { Opportunity } from './opportunity'\nimport { OpportunityEvent } from './opportunity-event'\nimport { OpportunityEventQuery } from './opportunity-event-query'\nimport { OpportunityMutation } from './opportunity-mutation'\nimport { OpportunityQuery } from './opportunity-query'\n\nexport const entities = [Opportunity, OpportunityEvent]\nexport const resolvers = [OpportunityQuery, OpportunityMutation, OpportunityEventQuery]\nexport const subscribers = []\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { User } from '@things-factory/auth-base';
|
|
2
|
+
import { Domain } from '@things-factory/shell';
|
|
3
|
+
import { OpportunityEvent } from './opportunity-event';
|
|
4
|
+
export declare class OpportunityEventQuery {
|
|
5
|
+
actor(row: OpportunityEvent): User | Promise<User>;
|
|
6
|
+
domain(row: OpportunityEvent): Domain | Promise<Domain>;
|
|
7
|
+
creator(row: OpportunityEvent): User | Promise<User>;
|
|
8
|
+
updater(row: OpportunityEvent): User | Promise<User>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpportunityEventQuery = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
7
|
+
const type_graphql_1 = require("type-graphql");
|
|
8
|
+
const opportunity_event_1 = require("./opportunity-event");
|
|
9
|
+
let OpportunityEventQuery = class OpportunityEventQuery {
|
|
10
|
+
actor(row) {
|
|
11
|
+
return row.actor ?? (row.actorId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.actorId }) : undefined);
|
|
12
|
+
}
|
|
13
|
+
domain(row) {
|
|
14
|
+
return row.domain ?? (row.domainId ? (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: row.domainId }) : undefined);
|
|
15
|
+
}
|
|
16
|
+
creator(row) {
|
|
17
|
+
return row.creator ?? (row.creatorId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.creatorId }) : undefined);
|
|
18
|
+
}
|
|
19
|
+
updater(row) {
|
|
20
|
+
return row.updater ?? (row.updaterId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.updaterId }) : undefined);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.OpportunityEventQuery = OpportunityEventQuery;
|
|
24
|
+
tslib_1.__decorate([
|
|
25
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
26
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
27
|
+
tslib_1.__metadata("design:type", Function),
|
|
28
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_event_1.OpportunityEvent]),
|
|
29
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
30
|
+
], OpportunityEventQuery.prototype, "actor", null);
|
|
31
|
+
tslib_1.__decorate([
|
|
32
|
+
(0, type_graphql_1.FieldResolver)(type => shell_1.Domain, { nullable: true }),
|
|
33
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
34
|
+
tslib_1.__metadata("design:type", Function),
|
|
35
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_event_1.OpportunityEvent]),
|
|
36
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
37
|
+
], OpportunityEventQuery.prototype, "domain", null);
|
|
38
|
+
tslib_1.__decorate([
|
|
39
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
40
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
41
|
+
tslib_1.__metadata("design:type", Function),
|
|
42
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_event_1.OpportunityEvent]),
|
|
43
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
44
|
+
], OpportunityEventQuery.prototype, "creator", null);
|
|
45
|
+
tslib_1.__decorate([
|
|
46
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
47
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
48
|
+
tslib_1.__metadata("design:type", Function),
|
|
49
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_event_1.OpportunityEvent]),
|
|
50
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
51
|
+
], OpportunityEventQuery.prototype, "updater", null);
|
|
52
|
+
exports.OpportunityEventQuery = OpportunityEventQuery = tslib_1.__decorate([
|
|
53
|
+
(0, type_graphql_1.Resolver)(opportunity_event_1.OpportunityEvent)
|
|
54
|
+
], OpportunityEventQuery);
|
|
55
|
+
//# sourceMappingURL=opportunity-event-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opportunity-event-query.js","sourceRoot":"","sources":["../../../server/service/opportunity/opportunity-event-query.ts"],"names":[],"mappings":";;;;AAAA,yDAAgD;AAChD,iDAA6D;AAC7D,+CAA4D;AAE5D,2DAAsD;AAG/C,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAEhC,KAAK,CAAS,GAAqB;QACjC,OAAO,GAAG,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,gBAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACpG,CAAC;IAGD,MAAM,CAAS,GAAqB;QAClC,OAAO,GAAG,CAAC,MAAM,IAAI,CAA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C,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACvC,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAM,oCAAgB;;oDAEpC;gCAnBU,qBAAqB;IADjC,IAAA,uBAAQ,EAAC,oCAAgB,CAAC;GACd,qBAAqB,CAoBjC","sourcesContent":["import { User } from '@things-factory/auth-base'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { FieldResolver, Resolver, Root } from 'type-graphql'\n\nimport { OpportunityEvent } from './opportunity-event'\n\n@Resolver(OpportunityEvent)\nexport class OpportunityEventQuery {\n @FieldResolver(type => User, { nullable: true })\n actor(@Root() row: OpportunityEvent) {\n return row.actor ?? (row.actorId ? getRepository(User).findOneBy({ id: row.actorId }) : undefined)\n }\n\n @FieldResolver(type => Domain, { nullable: true })\n domain(@Root() row: OpportunityEvent) {\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: OpportunityEvent) {\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: OpportunityEvent) {\n return row.updater ?? (row.updaterId ? getRepository(User).findOneBy({ id: row.updaterId }) : undefined)\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { User } from '@things-factory/auth-base';
|
|
2
|
+
import { Domain } from '@things-factory/shell';
|
|
3
|
+
import { Opportunity } from './opportunity';
|
|
4
|
+
import { OpportunityStage } from './opportunity-rules';
|
|
5
|
+
/** The same shape as QuotationEvent, with the stage it left and the stage and probability it took (ADR-0138 decision 6). */
|
|
6
|
+
export declare class OpportunityEvent {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
domain?: Domain;
|
|
9
|
+
domainId?: string;
|
|
10
|
+
opportunity: Opportunity;
|
|
11
|
+
opportunityId: string;
|
|
12
|
+
action: string;
|
|
13
|
+
fromStage?: OpportunityStage;
|
|
14
|
+
stage: OpportunityStage;
|
|
15
|
+
probability: number;
|
|
16
|
+
reason?: string;
|
|
17
|
+
snapshot: any;
|
|
18
|
+
actor?: User;
|
|
19
|
+
actorId?: string;
|
|
20
|
+
createdAt?: Date;
|
|
21
|
+
updatedAt?: Date;
|
|
22
|
+
deletedAt?: Date;
|
|
23
|
+
creator?: User;
|
|
24
|
+
creatorId?: string;
|
|
25
|
+
updater?: User;
|
|
26
|
+
updaterId?: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpportunityEvent = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
7
|
+
const type_graphql_1 = require("type-graphql");
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
const opportunity_1 = require("./opportunity");
|
|
10
|
+
const opportunity_rules_1 = require("./opportunity-rules");
|
|
11
|
+
/** The same shape as QuotationEvent, with the stage it left and the stage and probability it took (ADR-0138 decision 6). */
|
|
12
|
+
let OpportunityEvent = class OpportunityEvent {
|
|
13
|
+
};
|
|
14
|
+
exports.OpportunityEvent = OpportunityEvent;
|
|
15
|
+
tslib_1.__decorate([
|
|
16
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
17
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID),
|
|
18
|
+
tslib_1.__metadata("design:type", String)
|
|
19
|
+
], OpportunityEvent.prototype, "id", void 0);
|
|
20
|
+
tslib_1.__decorate([
|
|
21
|
+
(0, typeorm_1.ManyToOne)(type => shell_1.Domain),
|
|
22
|
+
(0, type_graphql_1.Field)(type => shell_1.Domain, { nullable: true }),
|
|
23
|
+
tslib_1.__metadata("design:type", shell_1.Domain)
|
|
24
|
+
], OpportunityEvent.prototype, "domain", void 0);
|
|
25
|
+
tslib_1.__decorate([
|
|
26
|
+
(0, typeorm_1.RelationId)((event) => event.domain),
|
|
27
|
+
tslib_1.__metadata("design:type", String)
|
|
28
|
+
], OpportunityEvent.prototype, "domainId", void 0);
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, typeorm_1.ManyToOne)(type => opportunity_1.Opportunity, { nullable: false }),
|
|
31
|
+
tslib_1.__metadata("design:type", opportunity_1.Opportunity)
|
|
32
|
+
], OpportunityEvent.prototype, "opportunity", void 0);
|
|
33
|
+
tslib_1.__decorate([
|
|
34
|
+
(0, typeorm_1.RelationId)((event) => event.opportunity),
|
|
35
|
+
(0, type_graphql_1.Field)({ description: 'The opportunity the event happened to' }),
|
|
36
|
+
tslib_1.__metadata("design:type", String)
|
|
37
|
+
], OpportunityEvent.prototype, "opportunityId", void 0);
|
|
38
|
+
tslib_1.__decorate([
|
|
39
|
+
(0, typeorm_1.Column)(),
|
|
40
|
+
(0, type_graphql_1.Field)({ description: 'What happened: CREATED, UPDATED, STAGED, WON or LOST' }),
|
|
41
|
+
tslib_1.__metadata("design:type", String)
|
|
42
|
+
], OpportunityEvent.prototype, "action", void 0);
|
|
43
|
+
tslib_1.__decorate([
|
|
44
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
45
|
+
(0, type_graphql_1.Field)(type => opportunity_rules_1.OpportunityStage, { nullable: true, description: 'The stage it moved from; empty when it was created' }),
|
|
46
|
+
tslib_1.__metadata("design:type", String)
|
|
47
|
+
], OpportunityEvent.prototype, "fromStage", void 0);
|
|
48
|
+
tslib_1.__decorate([
|
|
49
|
+
(0, typeorm_1.Column)(),
|
|
50
|
+
(0, type_graphql_1.Field)(type => opportunity_rules_1.OpportunityStage, { description: 'The stage it stood at after the event' }),
|
|
51
|
+
tslib_1.__metadata("design:type", String)
|
|
52
|
+
], OpportunityEvent.prototype, "stage", void 0);
|
|
53
|
+
tslib_1.__decorate([
|
|
54
|
+
(0, typeorm_1.Column)({ type: 'int' }),
|
|
55
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'The probability it had after the event, in percent' }),
|
|
56
|
+
tslib_1.__metadata("design:type", Number)
|
|
57
|
+
], OpportunityEvent.prototype, "probability", void 0);
|
|
58
|
+
tslib_1.__decorate([
|
|
59
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
60
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Why, when it was lost' }),
|
|
61
|
+
tslib_1.__metadata("design:type", String)
|
|
62
|
+
], OpportunityEvent.prototype, "reason", void 0);
|
|
63
|
+
tslib_1.__decorate([
|
|
64
|
+
(0, typeorm_1.Column)({ type: 'simple-json' }),
|
|
65
|
+
(0, type_graphql_1.Field)(type => shell_1.ScalarObject, { description: 'The opportunity as it stood after the event' }),
|
|
66
|
+
tslib_1.__metadata("design:type", Object)
|
|
67
|
+
], OpportunityEvent.prototype, "snapshot", void 0);
|
|
68
|
+
tslib_1.__decorate([
|
|
69
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
|
|
70
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
|
|
71
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
72
|
+
], OpportunityEvent.prototype, "actor", void 0);
|
|
73
|
+
tslib_1.__decorate([
|
|
74
|
+
(0, typeorm_1.RelationId)((event) => event.actor),
|
|
75
|
+
tslib_1.__metadata("design:type", String)
|
|
76
|
+
], OpportunityEvent.prototype, "actorId", void 0);
|
|
77
|
+
tslib_1.__decorate([
|
|
78
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
79
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When it happened' }),
|
|
80
|
+
tslib_1.__metadata("design:type", Date)
|
|
81
|
+
], OpportunityEvent.prototype, "createdAt", void 0);
|
|
82
|
+
tslib_1.__decorate([
|
|
83
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
84
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When the row last changed' }),
|
|
85
|
+
tslib_1.__metadata("design:type", Date)
|
|
86
|
+
], OpportunityEvent.prototype, "updatedAt", void 0);
|
|
87
|
+
tslib_1.__decorate([
|
|
88
|
+
(0, typeorm_1.DeleteDateColumn)(),
|
|
89
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When the row was deleted' }),
|
|
90
|
+
tslib_1.__metadata("design:type", Date)
|
|
91
|
+
], OpportunityEvent.prototype, "deletedAt", void 0);
|
|
92
|
+
tslib_1.__decorate([
|
|
93
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
|
|
94
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
|
|
95
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
96
|
+
], OpportunityEvent.prototype, "creator", void 0);
|
|
97
|
+
tslib_1.__decorate([
|
|
98
|
+
(0, typeorm_1.RelationId)((event) => event.creator),
|
|
99
|
+
tslib_1.__metadata("design:type", String)
|
|
100
|
+
], OpportunityEvent.prototype, "creatorId", void 0);
|
|
101
|
+
tslib_1.__decorate([
|
|
102
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
|
|
103
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
|
|
104
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
105
|
+
], OpportunityEvent.prototype, "updater", void 0);
|
|
106
|
+
tslib_1.__decorate([
|
|
107
|
+
(0, typeorm_1.RelationId)((event) => event.updater),
|
|
108
|
+
tslib_1.__metadata("design:type", String)
|
|
109
|
+
], OpportunityEvent.prototype, "updaterId", void 0);
|
|
110
|
+
exports.OpportunityEvent = OpportunityEvent = tslib_1.__decorate([
|
|
111
|
+
(0, typeorm_1.Entity)(),
|
|
112
|
+
(0, typeorm_1.Index)('ix_opportunity_event_0', (event) => [event.opportunity, event.createdAt]),
|
|
113
|
+
(0, type_graphql_1.ObjectType)({ description: 'Entity for OpportunityEvent — what happened to an opportunity, with the stage it moved from and to' })
|
|
114
|
+
], OpportunityEvent);
|
|
115
|
+
//# sourceMappingURL=opportunity-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opportunity-event.js","sourceRoot":"","sources":["../../../server/service/opportunity/opportunity-event.ts"],"names":[],"mappings":";;;;AAAA,yDAAgD;AAChD,iDAA4D;AAC5D,+CAAyD;AACzD,qCAAoJ;AAEpJ,+CAA2C;AAC3C,2DAAsD;AAEtD,4HAA4H;AAIrH,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CA2E5B,CAAA;AA3EY,4CAAgB;AAGlB;IAFR,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,CAAC;;4CACC;AAInB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IACzB,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCACjC,cAAM;gDAAA;AAGf;IADC,IAAA,oBAAU,EAAC,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;;kDACrC;AAGjB;IADC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,yBAAW,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;sCACvC,yBAAW;qDAAA;AAIxB;IAFC,IAAA,oBAAU,EAAC,CAAC,KAAuB,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC;IAC1D,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,uCAAuC,EAAE,CAAC;;uDAC3C;AAIrB;IAFC,IAAA,gBAAM,GAAE;IACR,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,sDAAsD,EAAE,CAAC;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AAA,yBAAU,EAAC,EAAE,WAAW,EAAE,oGAAoG,EAAE,CAAC;GACrH,gBAAgB,CA2E5B","sourcesContent":["import { User } from '@things-factory/auth-base'\nimport { Domain, ScalarObject } from '@things-factory/shell'\nimport { Field, ID, Int, ObjectType } from 'type-graphql'\nimport { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'\n\nimport { Opportunity } from './opportunity'\nimport { OpportunityStage } from './opportunity-rules'\n\n/** The same shape as QuotationEvent, with the stage it left and the stage and probability it took (ADR-0138 decision 6). */\n@Entity()\n@Index('ix_opportunity_event_0', (event: OpportunityEvent) => [event.opportunity, event.createdAt])\n@ObjectType({ description: 'Entity for OpportunityEvent — what happened to an opportunity, with the stage it moved from and to' })\nexport class OpportunityEvent {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true })\n domain?: Domain\n\n @RelationId((event: OpportunityEvent) => event.domain)\n domainId?: string\n\n @ManyToOne(type => Opportunity, { nullable: false })\n opportunity: Opportunity\n\n @RelationId((event: OpportunityEvent) => event.opportunity)\n @Field({ description: 'The opportunity the event happened to' })\n opportunityId: string\n\n @Column()\n @Field({ description: 'What happened: CREATED, UPDATED, STAGED, WON or LOST' })\n action: string\n\n @Column({ nullable: true })\n @Field(type => OpportunityStage, { nullable: true, description: 'The stage it moved from; empty when it was created' })\n fromStage?: OpportunityStage\n\n @Column()\n @Field(type => OpportunityStage, { description: 'The stage it stood at after the event' })\n stage: OpportunityStage\n\n @Column({ type: 'int' })\n @Field(type => Int, { description: 'The probability it had after the event, in percent' })\n probability: number\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Why, when it was lost' })\n reason?: string\n\n @Column({ type: 'simple-json' })\n @Field(type => ScalarObject, { description: 'The opportunity as it stood after the event' })\n snapshot: any\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true })\n actor?: User\n\n @RelationId((event: OpportunityEvent) => event.actor)\n actorId?: string\n\n @CreateDateColumn()\n @Field({ nullable: true, description: 'When it happened' })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true, description: 'When the row last changed' })\n updatedAt?: Date\n\n @DeleteDateColumn()\n @Field({ nullable: true, description: 'When the row was deleted' })\n deletedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true })\n creator?: User\n\n @RelationId((event: OpportunityEvent) => event.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true })\n updater?: User\n\n @RelationId((event: OpportunityEvent) => event.updater)\n updaterId?: string\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Opportunity } from './opportunity';
|
|
2
|
+
import { NewOpportunity } from './opportunity-type';
|
|
3
|
+
export declare class OpportunityMutation {
|
|
4
|
+
createOpportunity(opportunity: NewOpportunity, context: ResolverContext): Promise<Opportunity>;
|
|
5
|
+
updateOpportunity(id: string, opportunity: NewOpportunity, context: ResolverContext): Promise<Opportunity>;
|
|
6
|
+
loseOpportunity(id: string, reason: string, closedOn: string, context: ResolverContext): Promise<Opportunity>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpportunityMutation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const shell_1 = require("@things-factory/shell");
|
|
6
|
+
const type_graphql_1 = require("type-graphql");
|
|
7
|
+
const opportunity_1 = require("./opportunity");
|
|
8
|
+
const opportunity_rules_1 = require("./opportunity-rules");
|
|
9
|
+
const opportunity_service_1 = require("./opportunity-service");
|
|
10
|
+
const opportunity_type_1 = require("./opportunity-type");
|
|
11
|
+
/* Winning has no door here: the application that turns a won opportunity into its own record closes it (ADR-0138 decision 8). */
|
|
12
|
+
let OpportunityMutation = class OpportunityMutation {
|
|
13
|
+
createOpportunity(opportunity, context) {
|
|
14
|
+
const { tx, domain, user } = context.state;
|
|
15
|
+
return (0, opportunity_service_1.saveOpportunity)(tx, domain, user, opportunity);
|
|
16
|
+
}
|
|
17
|
+
updateOpportunity(id, opportunity, context) {
|
|
18
|
+
const { tx, domain, user } = context.state;
|
|
19
|
+
return (0, opportunity_service_1.saveOpportunity)(tx, domain, user, opportunity, id);
|
|
20
|
+
}
|
|
21
|
+
loseOpportunity(id, reason, closedOn, context) {
|
|
22
|
+
const { tx, domain, user } = context.state;
|
|
23
|
+
return (0, opportunity_service_1.closeOpportunity)(tx, domain, user, id, opportunity_rules_1.OpportunityStage.LOST, { reason, closedOn });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.OpportunityMutation = OpportunityMutation;
|
|
27
|
+
tslib_1.__decorate([
|
|
28
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
29
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "mutation", domainOwnerGranted: true)'),
|
|
30
|
+
(0, type_graphql_1.Mutation)(type => opportunity_1.Opportunity, { description: 'To create an opportunity' }),
|
|
31
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('opportunity')),
|
|
32
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
33
|
+
tslib_1.__metadata("design:type", Function),
|
|
34
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_type_1.NewOpportunity, Object]),
|
|
35
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
36
|
+
], OpportunityMutation.prototype, "createOpportunity", null);
|
|
37
|
+
tslib_1.__decorate([
|
|
38
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
39
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "mutation", domainOwnerGranted: true)'),
|
|
40
|
+
(0, type_graphql_1.Mutation)(type => opportunity_1.Opportunity, { description: 'To change an open opportunity, move it to another open stage, or open a lost one again' }),
|
|
41
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
42
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('opportunity')),
|
|
43
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
44
|
+
tslib_1.__metadata("design:type", Function),
|
|
45
|
+
tslib_1.__metadata("design:paramtypes", [String, opportunity_type_1.NewOpportunity, Object]),
|
|
46
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
47
|
+
], OpportunityMutation.prototype, "updateOpportunity", null);
|
|
48
|
+
tslib_1.__decorate([
|
|
49
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
50
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "mutation", domainOwnerGranted: true)'),
|
|
51
|
+
(0, type_graphql_1.Mutation)(type => opportunity_1.Opportunity, { description: 'To close an open opportunity as lost, with the reason' }),
|
|
52
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
53
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('reason')),
|
|
54
|
+
tslib_1.__param(2, (0, type_graphql_1.Arg)('closedOn', { nullable: true })),
|
|
55
|
+
tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
|
|
56
|
+
tslib_1.__metadata("design:type", Function),
|
|
57
|
+
tslib_1.__metadata("design:paramtypes", [String, String, String, Object]),
|
|
58
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
59
|
+
], OpportunityMutation.prototype, "loseOpportunity", null);
|
|
60
|
+
exports.OpportunityMutation = OpportunityMutation = tslib_1.__decorate([
|
|
61
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
|
|
62
|
+
(0, type_graphql_1.Resolver)(opportunity_1.Opportunity)
|
|
63
|
+
], OpportunityMutation);
|
|
64
|
+
//# sourceMappingURL=opportunity-mutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opportunity-mutation.js","sourceRoot":"","sources":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,aAAa,CAAC,CAAA;IAA+B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAtB,iCAAc;;4DAGhE;AAKD;IAHC,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,gFAAgF,CAAC;IAC3F,IAAA,uBAAQ,EAAC,IAAI,CAAC,EAAE,CAAC,yBAAW,EAAE,EAAE,WAAW,EAAE,wFAAwF,EAAE,CAAC;IACtH,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,EAAC,aAAa,CAAC,CAAA;IAA+B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;qDAAtB,iCAAc;;4DAGvF;AAKD;IAHC,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,gFAAgF,CAAC;IAC3F,IAAA,uBAAQ,EAAC,IAAI,CAAC,EAAE,CAAC,yBAAW,EAAE,EAAE,WAAW,EAAE,uDAAuD,EAAE,CAAC;IACvF,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,EAAC,QAAQ,CAAC,CAAA;IAAkB,mBAAA,IAAA,kBAAG,EAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAAoB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DAGlI;8BAvBU,mBAAmB;IAF/B,IAAA,4BAAa,EAAC,qBAAa,CAAC;IAC5B,IAAA,uBAAQ,EAAC,yBAAW,CAAC;GACT,mBAAmB,CAwB/B","sourcesContent":["import { SpeakRefusals } from '@things-factory/shell'\nimport { Arg, Ctx, Directive, Mutation, Resolver, UseMiddleware } from 'type-graphql'\n\nimport { Opportunity } from './opportunity'\nimport { OpportunityStage } from './opportunity-rules'\nimport { closeOpportunity, saveOpportunity } from './opportunity-service'\nimport { NewOpportunity } from './opportunity-type'\n\n/* Winning has no door here: the application that turns a won opportunity into its own record closes it (ADR-0138 decision 8). */\n@UseMiddleware(SpeakRefusals)\n@Resolver(Opportunity)\nexport class OpportunityMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"sales\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Opportunity, { description: 'To create an opportunity' })\n createOpportunity(@Arg('opportunity') opportunity: NewOpportunity, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveOpportunity(tx, domain, user, opportunity)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"sales\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Opportunity, { description: 'To change an open opportunity, move it to another open stage, or open a lost one again' })\n updateOpportunity(@Arg('id') id: string, @Arg('opportunity') opportunity: NewOpportunity, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return saveOpportunity(tx, domain, user, opportunity, id)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"sales\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(type => Opportunity, { description: 'To close an open opportunity as lost, with the reason' })\n loseOpportunity(@Arg('id') id: string, @Arg('reason') reason: string, @Arg('closedOn', { nullable: true }) closedOn: string, @Ctx() context: ResolverContext) {\n const { tx, domain, user } = context.state\n return closeOpportunity(tx, domain, user, id, OpportunityStage.LOST, { reason, closedOn })\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { User } from '@things-factory/auth-base';
|
|
2
|
+
import { Counterparty } from '@things-factory/biz-base';
|
|
3
|
+
import { Domain, ListParam } from '@things-factory/shell';
|
|
4
|
+
import { Quotation } from '../quotation/quotation';
|
|
5
|
+
import { Opportunity } from './opportunity';
|
|
6
|
+
import { OpportunityEvent } from './opportunity-event';
|
|
7
|
+
import { OpportunityList, OpportunityStageDefault } from './opportunity-type';
|
|
8
|
+
export declare class OpportunityQuery {
|
|
9
|
+
opportunity(id: string, context: ResolverContext): Promise<Opportunity>;
|
|
10
|
+
opportunities(params: ListParam, context: ResolverContext): Promise<OpportunityList>;
|
|
11
|
+
opportunityEvents(opportunityId: string, context: ResolverContext): Promise<OpportunityEvent[]>;
|
|
12
|
+
opportunityStages(): OpportunityStageDefault[];
|
|
13
|
+
opportunityOwners(context: ResolverContext): Promise<User[]>;
|
|
14
|
+
quotations(row: Opportunity): Promise<Quotation[]>;
|
|
15
|
+
counterparty(row: Opportunity): Counterparty | Promise<Counterparty>;
|
|
16
|
+
endCustomer(row: Opportunity): Counterparty | Promise<Counterparty>;
|
|
17
|
+
owner(row: Opportunity): User | Promise<User>;
|
|
18
|
+
domain(row: Opportunity): Domain | Promise<Domain>;
|
|
19
|
+
creator(row: Opportunity): User | Promise<User>;
|
|
20
|
+
updater(row: Opportunity): User | Promise<User>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpportunityQuery = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
|
+
const biz_base_1 = require("@things-factory/biz-base");
|
|
7
|
+
const shell_1 = require("@things-factory/shell");
|
|
8
|
+
const type_graphql_1 = require("type-graphql");
|
|
9
|
+
const quotation_1 = require("../quotation/quotation");
|
|
10
|
+
const quotation_service_1 = require("../quotation/quotation-service");
|
|
11
|
+
const opportunity_1 = require("./opportunity");
|
|
12
|
+
const opportunity_event_1 = require("./opportunity-event");
|
|
13
|
+
const opportunity_rules_1 = require("./opportunity-rules");
|
|
14
|
+
const opportunity_type_1 = require("./opportunity-type");
|
|
15
|
+
let OpportunityQuery = class OpportunityQuery {
|
|
16
|
+
opportunity(id, context) {
|
|
17
|
+
return (0, shell_1.getRepository)(opportunity_1.Opportunity).findOne({ where: { id, domain: { id: context.state.domain.id } } });
|
|
18
|
+
}
|
|
19
|
+
async opportunities(params, context) {
|
|
20
|
+
const query = (0, shell_1.getQueryBuilderFromListParams)({
|
|
21
|
+
domain: context.state.domain,
|
|
22
|
+
params,
|
|
23
|
+
repository: (0, shell_1.getRepository)(opportunity_1.Opportunity),
|
|
24
|
+
searchables: ['name', 'description']
|
|
25
|
+
});
|
|
26
|
+
const [items, total] = await query.getManyAndCount();
|
|
27
|
+
return { items, total };
|
|
28
|
+
}
|
|
29
|
+
opportunityEvents(opportunityId, context) {
|
|
30
|
+
return (0, shell_1.getRepository)(opportunity_event_1.OpportunityEvent).find({ where: { domain: { id: context.state.domain.id }, opportunity: { id: opportunityId } }, order: { createdAt: 'ASC' } });
|
|
31
|
+
}
|
|
32
|
+
opportunityStages() {
|
|
33
|
+
return Object.values(opportunity_rules_1.OpportunityStage).map(stage => ({ stage, probability: opportunity_rules_1.STAGE_PROBABILITY[stage], open: (0, opportunity_rules_1.isOpen)(stage) }));
|
|
34
|
+
}
|
|
35
|
+
opportunityOwners(context) {
|
|
36
|
+
return (0, auth_base_1.getDomainAssignees)(context.state.domain);
|
|
37
|
+
}
|
|
38
|
+
quotations(row) {
|
|
39
|
+
return (0, quotation_service_1.quotationsOfOpportunity)(undefined, { id: row.domainId }, row.id);
|
|
40
|
+
}
|
|
41
|
+
counterparty(row) {
|
|
42
|
+
return row.counterparty ?? (row.counterpartyId ? (0, shell_1.getRepository)(biz_base_1.Counterparty).findOneBy({ id: row.counterpartyId }) : undefined);
|
|
43
|
+
}
|
|
44
|
+
endCustomer(row) {
|
|
45
|
+
return row.endCustomer ?? (row.endCustomerId ? (0, shell_1.getRepository)(biz_base_1.Counterparty).findOneBy({ id: row.endCustomerId }) : undefined);
|
|
46
|
+
}
|
|
47
|
+
owner(row) {
|
|
48
|
+
return row.owner ?? (row.ownerId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.ownerId }) : undefined);
|
|
49
|
+
}
|
|
50
|
+
domain(row) {
|
|
51
|
+
return row.domain ?? (row.domainId ? (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: row.domainId }) : undefined);
|
|
52
|
+
}
|
|
53
|
+
creator(row) {
|
|
54
|
+
return row.creator ?? (row.creatorId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.creatorId }) : undefined);
|
|
55
|
+
}
|
|
56
|
+
updater(row) {
|
|
57
|
+
return row.updater ?? (row.updaterId ? (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: row.updaterId }) : undefined);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.OpportunityQuery = OpportunityQuery;
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "query", domainOwnerGranted: true)'),
|
|
63
|
+
(0, type_graphql_1.Query)(type => opportunity_1.Opportunity, { nullable: true, description: 'To fetch an opportunity' }),
|
|
64
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
65
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
66
|
+
tslib_1.__metadata("design:type", Function),
|
|
67
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
68
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
69
|
+
], OpportunityQuery.prototype, "opportunity", null);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "query", domainOwnerGranted: true)'),
|
|
72
|
+
(0, type_graphql_1.Query)(type => opportunity_type_1.OpportunityList, { description: 'To fetch a page of opportunities' }),
|
|
73
|
+
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
|
74
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
75
|
+
tslib_1.__metadata("design:type", Function),
|
|
76
|
+
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
77
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
78
|
+
], OpportunityQuery.prototype, "opportunities", null);
|
|
79
|
+
tslib_1.__decorate([
|
|
80
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "query", domainOwnerGranted: true)'),
|
|
81
|
+
(0, type_graphql_1.Query)(type => [opportunity_event_1.OpportunityEvent], { description: 'To fetch what happened to an opportunity, oldest first' }),
|
|
82
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('opportunityId')),
|
|
83
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
84
|
+
tslib_1.__metadata("design:type", Function),
|
|
85
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
86
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
87
|
+
], OpportunityQuery.prototype, "opportunityEvents", null);
|
|
88
|
+
tslib_1.__decorate([
|
|
89
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "query", domainOwnerGranted: true)'),
|
|
90
|
+
(0, type_graphql_1.Query)(type => [opportunity_type_1.OpportunityStageDefault], { description: 'To fetch the stages in order, with the probability each gives' }),
|
|
91
|
+
tslib_1.__metadata("design:type", Function),
|
|
92
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
93
|
+
tslib_1.__metadata("design:returntype", Array)
|
|
94
|
+
], OpportunityQuery.prototype, "opportunityStages", null);
|
|
95
|
+
tslib_1.__decorate([
|
|
96
|
+
(0, type_graphql_1.Directive)('@privilege(category: "sales", privilege: "query", domainOwnerGranted: true)'),
|
|
97
|
+
(0, type_graphql_1.Query)(type => [auth_base_1.User], { description: 'To fetch the people an opportunity may be put in the charge of' }),
|
|
98
|
+
tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
|
|
99
|
+
tslib_1.__metadata("design:type", Function),
|
|
100
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
101
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
102
|
+
], OpportunityQuery.prototype, "opportunityOwners", null);
|
|
103
|
+
tslib_1.__decorate([
|
|
104
|
+
(0, type_graphql_1.FieldResolver)(type => [quotation_1.Quotation], { description: 'The quotations that answer the opportunity, every version' }),
|
|
105
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
106
|
+
tslib_1.__metadata("design:type", Function),
|
|
107
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_1.Opportunity]),
|
|
108
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
109
|
+
], OpportunityQuery.prototype, "quotations", null);
|
|
110
|
+
tslib_1.__decorate([
|
|
111
|
+
(0, type_graphql_1.FieldResolver)(type => biz_base_1.Counterparty, { nullable: true }),
|
|
112
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
113
|
+
tslib_1.__metadata("design:type", Function),
|
|
114
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_1.Opportunity]),
|
|
115
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
116
|
+
], OpportunityQuery.prototype, "counterparty", null);
|
|
117
|
+
tslib_1.__decorate([
|
|
118
|
+
(0, type_graphql_1.FieldResolver)(type => biz_base_1.Counterparty, { nullable: true }),
|
|
119
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
120
|
+
tslib_1.__metadata("design:type", Function),
|
|
121
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_1.Opportunity]),
|
|
122
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
123
|
+
], OpportunityQuery.prototype, "endCustomer", null);
|
|
124
|
+
tslib_1.__decorate([
|
|
125
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
126
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
127
|
+
tslib_1.__metadata("design:type", Function),
|
|
128
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_1.Opportunity]),
|
|
129
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
130
|
+
], OpportunityQuery.prototype, "owner", null);
|
|
131
|
+
tslib_1.__decorate([
|
|
132
|
+
(0, type_graphql_1.FieldResolver)(type => shell_1.Domain, { nullable: true }),
|
|
133
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
134
|
+
tslib_1.__metadata("design:type", Function),
|
|
135
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_1.Opportunity]),
|
|
136
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
137
|
+
], OpportunityQuery.prototype, "domain", null);
|
|
138
|
+
tslib_1.__decorate([
|
|
139
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
140
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
141
|
+
tslib_1.__metadata("design:type", Function),
|
|
142
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_1.Opportunity]),
|
|
143
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
144
|
+
], OpportunityQuery.prototype, "creator", null);
|
|
145
|
+
tslib_1.__decorate([
|
|
146
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
147
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
148
|
+
tslib_1.__metadata("design:type", Function),
|
|
149
|
+
tslib_1.__metadata("design:paramtypes", [opportunity_1.Opportunity]),
|
|
150
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
151
|
+
], OpportunityQuery.prototype, "updater", null);
|
|
152
|
+
exports.OpportunityQuery = OpportunityQuery = tslib_1.__decorate([
|
|
153
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
|
|
154
|
+
(0, type_graphql_1.Resolver)(opportunity_1.Opportunity)
|
|
155
|
+
], OpportunityQuery);
|
|
156
|
+
//# sourceMappingURL=opportunity-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opportunity-query.js","sourceRoot":"","sources":["../../../server/service/opportunity/opportunity-query.ts"],"names":[],"mappings":";;;;AAAA,yDAAoE;AACpE,uDAAuD;AACvD,iDAAsH;AACtH,+CAA6G;AAE7G,sDAAkD;AAClD,sEAAwE;AACxE,+CAA2C;AAC3C,2DAAsD;AACtD,2DAAiF;A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AAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACzC,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAM,yBAAW;;6CAE7B;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC1C,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAM,yBAAW;;8CAE9B;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACvC,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAM,yBAAW;;+CAE/B;AAGD;IADC,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACvC,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAM,yBAAW;;+CAE/B;2BAvEU,gBAAgB;IAF5B,IAAA,4BAAa,EAAC,qBAAa,CAAC;IAC5B,IAAA,uBAAQ,EAAC,yBAAW,CAAC;GACT,gBAAgB,CAwE5B","sourcesContent":["import { getDomainAssignees, User } from '@things-factory/auth-base'\nimport { Counterparty } from '@things-factory/biz-base'\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/quotation'\nimport { quotationsOfOpportunity } from '../quotation/quotation-service'\nimport { Opportunity } from './opportunity'\nimport { OpportunityEvent } from './opportunity-event'\nimport { isOpen, OpportunityStage, STAGE_PROBABILITY } from './opportunity-rules'\nimport { OpportunityList, OpportunityStageDefault } from './opportunity-type'\n\n@UseMiddleware(SpeakRefusals)\n@Resolver(Opportunity)\nexport class OpportunityQuery {\n @Directive('@privilege(category: \"sales\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => Opportunity, { nullable: true, description: 'To fetch an opportunity' })\n opportunity(@Arg('id') id: string, @Ctx() context: ResolverContext) {\n return getRepository(Opportunity).findOne({ where: { id, domain: { id: context.state.domain.id } } })\n }\n\n @Directive('@privilege(category: \"sales\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => OpportunityList, { description: 'To fetch a page of opportunities' })\n async opportunities(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<OpportunityList> {\n const query = getQueryBuilderFromListParams({\n domain: context.state.domain,\n params,\n repository: getRepository(Opportunity),\n searchables: ['name', 'description']\n })\n const [items, total] = await query.getManyAndCount()\n return { items, total }\n }\n\n @Directive('@privilege(category: \"sales\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => [OpportunityEvent], { description: 'To fetch what happened to an opportunity, oldest first' })\n opportunityEvents(@Arg('opportunityId') opportunityId: string, @Ctx() context: ResolverContext) {\n return getRepository(OpportunityEvent).find({ where: { domain: { id: context.state.domain.id }, opportunity: { id: opportunityId } }, order: { createdAt: 'ASC' } })\n }\n\n @Directive('@privilege(category: \"sales\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => [OpportunityStageDefault], { description: 'To fetch the stages in order, with the probability each gives' })\n opportunityStages(): OpportunityStageDefault[] {\n return Object.values(OpportunityStage).map(stage => ({ stage, probability: STAGE_PROBABILITY[stage], open: isOpen(stage) }))\n }\n\n @Directive('@privilege(category: \"sales\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(type => [User], { description: 'To fetch the people an opportunity may be put in the charge of' })\n opportunityOwners(@Ctx() context: ResolverContext) {\n return getDomainAssignees(context.state.domain)\n }\n\n @FieldResolver(type => [Quotation], { description: 'The quotations that answer the opportunity, every version' })\n quotations(@Root() row: Opportunity) {\n return quotationsOfOpportunity(undefined, { id: row.domainId } as Domain, row.id)\n }\n\n @FieldResolver(type => Counterparty, { nullable: true })\n counterparty(@Root() row: Opportunity) {\n return row.counterparty ?? (row.counterpartyId ? getRepository(Counterparty).findOneBy({ id: row.counterpartyId }) : undefined)\n }\n\n @FieldResolver(type => Counterparty, { nullable: true })\n endCustomer(@Root() row: Opportunity) {\n return row.endCustomer ?? (row.endCustomerId ? getRepository(Counterparty).findOneBy({ id: row.endCustomerId }) : undefined)\n }\n\n @FieldResolver(type => User, { nullable: true })\n owner(@Root() row: Opportunity) {\n return row.owner ?? (row.ownerId ? getRepository(User).findOneBy({ id: row.ownerId }) : undefined)\n }\n\n @FieldResolver(type => Domain, { nullable: true })\n domain(@Root() row: Opportunity) {\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: Opportunity) {\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: Opportunity) {\n return row.updater ?? (row.updaterId ? getRepository(User).findOneBy({ id: row.updaterId }) : undefined)\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare enum OpportunityStage {
|
|
2
|
+
LEAD = "LEAD",
|
|
3
|
+
PROPOSAL = "PROPOSAL",
|
|
4
|
+
QUOTED = "QUOTED",
|
|
5
|
+
NEGOTIATION = "NEGOTIATION",
|
|
6
|
+
WON = "WON",
|
|
7
|
+
LOST = "LOST"
|
|
8
|
+
}
|
|
9
|
+
/** The stages a person moves an opportunity through, in order; the two after them close it. */
|
|
10
|
+
export declare const OPEN_STAGES: OpportunityStage[];
|
|
11
|
+
export declare const STAGE_PROBABILITY: Record<OpportunityStage, number>;
|
|
12
|
+
export declare const isOpen: (stage: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether an opportunity may go from one stage to another. A person moves an open one to any open stage, or closes it
|
|
15
|
+
* as lost; a lost one may be opened again. Winning closes it for good — an application turns the win into its own
|
|
16
|
+
* record (a contract) and only it closes an opportunity as won.
|
|
17
|
+
*/
|
|
18
|
+
export declare function stageMove(from: string, to: string): boolean;
|
|
19
|
+
/** The probability an opportunity keeps after a stage change: the one a person gave, or the stage's own. */
|
|
20
|
+
export declare function probabilityAfter(stage: OpportunityStage, given?: number | null): number;
|
|
21
|
+
export declare const validProbability: (value: unknown) => boolean;
|
|
22
|
+
export declare const validMonth: (value: unknown) => boolean;
|