@deenruv/product-badges-plugin 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +45 -0
  3. package/dist/plugin-server/entities/Badge.d.ts +12 -0
  4. package/dist/plugin-server/entities/Badge.js +46 -0
  5. package/dist/plugin-server/entities/BadgeTranslation.d.ts +10 -0
  6. package/dist/plugin-server/entities/BadgeTranslation.js +40 -0
  7. package/dist/plugin-server/extensions/badge.extension.d.ts +3 -0
  8. package/dist/plugin-server/extensions/badge.extension.js +79 -0
  9. package/dist/plugin-server/index.d.ts +2 -0
  10. package/dist/plugin-server/index.js +35 -0
  11. package/dist/plugin-server/resolvers/badge-admin.resolver.d.ts +19 -0
  12. package/dist/plugin-server/resolvers/badge-admin.resolver.js +79 -0
  13. package/dist/plugin-server/resolvers/badge-entity.resolver.d.ts +7 -0
  14. package/dist/plugin-server/resolvers/badge-entity.resolver.js +39 -0
  15. package/dist/plugin-server/services/badge.service.d.ts +15 -0
  16. package/dist/plugin-server/services/badge.service.js +112 -0
  17. package/dist/plugin-server/types.d.ts +11 -0
  18. package/dist/plugin-server/types.js +2 -0
  19. package/dist/plugin-server/zeus/const.d.ts +6 -0
  20. package/dist/plugin-server/zeus/const.js +3841 -0
  21. package/dist/plugin-server/zeus/index.d.ts +19707 -0
  22. package/dist/plugin-server/zeus/index.js +1100 -0
  23. package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
  24. package/dist/plugin-server/zeus/typedDocumentNode.js +16 -0
  25. package/dist/plugin-ui/components/Badges.d.ts +5 -0
  26. package/dist/plugin-ui/components/Badges.js +82 -0
  27. package/dist/plugin-ui/components/BadgesModal.d.ts +10 -0
  28. package/dist/plugin-ui/components/BadgesModal.js +69 -0
  29. package/dist/plugin-ui/components/index.d.ts +1 -0
  30. package/dist/plugin-ui/components/index.js +1 -0
  31. package/dist/plugin-ui/graphql/mutations.d.ts +33 -0
  32. package/dist/plugin-ui/graphql/mutations.js +29 -0
  33. package/dist/plugin-ui/graphql/queries.d.ts +9 -0
  34. package/dist/plugin-ui/graphql/queries.js +14 -0
  35. package/dist/plugin-ui/graphql/selectors.d.ts +11 -0
  36. package/dist/plugin-ui/graphql/selectors.js +12 -0
  37. package/dist/plugin-ui/index.d.ts +1 -0
  38. package/dist/plugin-ui/index.js +14 -0
  39. package/dist/plugin-ui/locales/en/badges.json +25 -0
  40. package/dist/plugin-ui/locales/en/index.d.ts +26 -0
  41. package/dist/plugin-ui/locales/en/index.js +2 -0
  42. package/dist/plugin-ui/locales/pl/badges.json +25 -0
  43. package/dist/plugin-ui/locales/pl/index.d.ts +26 -0
  44. package/dist/plugin-ui/locales/pl/index.js +2 -0
  45. package/dist/plugin-ui/translation-ns.d.ts +1 -0
  46. package/dist/plugin-ui/translation-ns.js +1 -0
  47. package/dist/plugin-ui/tsconfig.json +18 -0
  48. package/dist/plugin-ui/zeus/const.d.ts +6 -0
  49. package/dist/plugin-ui/zeus/const.js +3838 -0
  50. package/dist/plugin-ui/zeus/index.d.ts +19707 -0
  51. package/dist/plugin-ui/zeus/index.js +1092 -0
  52. package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
  53. package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
  54. package/package.json +48 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ # License 1
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2025-present Aexol
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+
13
+ # License 2
14
+
15
+ The MIT License
16
+
17
+ Copyright (c) 2018-2025 Michael Bromley
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @deenruv/product-badges-plugin
2
+
3
+ Plugin that adds translatable, color-coded badges to products. Badges can be managed through the Admin API and displayed on the storefront via the Shop API, enabling visual labels like "New", "Sale", "Bestseller", etc.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @deenruv/product-badges-plugin
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ ```typescript
14
+ import { BadgesServerPlugin } from '@deenruv/product-badges-plugin';
15
+
16
+ // In your Deenruv server config:
17
+ plugins: [
18
+ BadgesServerPlugin,
19
+ ]
20
+ ```
21
+
22
+ ## Features
23
+
24
+ - Translatable badge names with multi-language support
25
+ - Color-coded badges with customizable hex colors
26
+ - CRUD operations for badges via the Admin API
27
+ - Badges associated with individual products
28
+ - Both Admin and Shop API extensions for full badge management and display
29
+
30
+ ## Admin UI
31
+
32
+ This plugin extends the admin UI with a badge management interface on the product detail page, including a badge list, a creation/edit modal with color picker and translation inputs, and badge removal functionality.
33
+
34
+ ## API Extensions
35
+
36
+ ### Admin API
37
+
38
+ - **Query** `getProductBadges(input: GetProductBadgesInput!): [Badge!]` — Returns all badges for a given product
39
+ - **Mutation** `createBadge(input: CreateBadgeInput!): Badge!` — Creates a new badge with color and translations
40
+ - **Mutation** `editBadge(input: EditBadgeInput!): Badge!` — Updates a badge's color and/or translations
41
+ - **Mutation** `removeBadge(input: RemoveBadgeInput!): Boolean!` — Removes a badge by ID
42
+
43
+ ### Shop API
44
+
45
+ - **Field** `Product.badges: [Badge!]` — Returns badges associated with a product, including translations
@@ -0,0 +1,12 @@
1
+ import { DeenruvEntity } from "@deenruv/core";
2
+ import type { Relation } from "typeorm";
3
+ import type { DeepPartial, LocaleString, Translatable, Translation } from "@deenruv/core";
4
+ import { Product } from "@deenruv/core";
5
+ export declare class Badge extends DeenruvEntity implements Translatable {
6
+ constructor(input?: DeepPartial<Badge>);
7
+ product: Relation<Product>;
8
+ name: LocaleString;
9
+ color: string;
10
+ productId: string;
11
+ translations: Relation<Array<Translation<Badge>>>;
12
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Badge = void 0;
13
+ const core_1 = require("@deenruv/core");
14
+ const typeorm_1 = require("typeorm");
15
+ const core_2 = require("@deenruv/core");
16
+ const BadgeTranslation_js_1 = require("./BadgeTranslation.js");
17
+ let Badge = class Badge extends core_1.DeenruvEntity {
18
+ constructor(input) {
19
+ super(input);
20
+ }
21
+ };
22
+ exports.Badge = Badge;
23
+ __decorate([
24
+ (0, typeorm_1.ManyToOne)(() => core_2.Product, (product) => product.badges, {
25
+ onDelete: "CASCADE",
26
+ }),
27
+ __metadata("design:type", Object)
28
+ ], Badge.prototype, "product", void 0);
29
+ __decorate([
30
+ (0, typeorm_1.Column)(),
31
+ __metadata("design:type", String)
32
+ ], Badge.prototype, "color", void 0);
33
+ __decorate([
34
+ (0, typeorm_1.Column)(),
35
+ __metadata("design:type", String)
36
+ ], Badge.prototype, "productId", void 0);
37
+ __decorate([
38
+ (0, typeorm_1.OneToMany)(() => BadgeTranslation_js_1.BadgeTranslation, (translation) => translation.base, {
39
+ eager: true,
40
+ }),
41
+ __metadata("design:type", Object)
42
+ ], Badge.prototype, "translations", void 0);
43
+ exports.Badge = Badge = __decorate([
44
+ (0, typeorm_1.Entity)(),
45
+ __metadata("design:paramtypes", [Object])
46
+ ], Badge);
@@ -0,0 +1,10 @@
1
+ import { LanguageCode, DeenruvEntity } from "@deenruv/core";
2
+ import type { DeepPartial } from "@deenruv/core";
3
+ import { Badge } from "./Badge.js";
4
+ import type { Relation } from "typeorm";
5
+ export declare class BadgeTranslation extends DeenruvEntity {
6
+ constructor(input?: DeepPartial<BadgeTranslation>);
7
+ base: Relation<Badge>;
8
+ languageCode: LanguageCode;
9
+ name: string;
10
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.BadgeTranslation = void 0;
13
+ const core_1 = require("@deenruv/core");
14
+ const typeorm_1 = require("typeorm");
15
+ const Badge_js_1 = require("./Badge.js");
16
+ let BadgeTranslation = class BadgeTranslation extends core_1.DeenruvEntity {
17
+ constructor(input) {
18
+ super(input);
19
+ }
20
+ };
21
+ exports.BadgeTranslation = BadgeTranslation;
22
+ __decorate([
23
+ (0, typeorm_1.Index)(),
24
+ (0, typeorm_1.ManyToOne)(() => Badge_js_1.Badge, (base) => base.translations, {
25
+ onDelete: "CASCADE",
26
+ }),
27
+ __metadata("design:type", Object)
28
+ ], BadgeTranslation.prototype, "base", void 0);
29
+ __decorate([
30
+ (0, typeorm_1.Column)("varchar"),
31
+ __metadata("design:type", String)
32
+ ], BadgeTranslation.prototype, "languageCode", void 0);
33
+ __decorate([
34
+ (0, typeorm_1.Column)(),
35
+ __metadata("design:type", String)
36
+ ], BadgeTranslation.prototype, "name", void 0);
37
+ exports.BadgeTranslation = BadgeTranslation = __decorate([
38
+ (0, typeorm_1.Entity)(),
39
+ __metadata("design:paramtypes", [Object])
40
+ ], BadgeTranslation);
@@ -0,0 +1,3 @@
1
+ import graphql from "graphql";
2
+ export declare const ShopExtension: graphql.DocumentNode;
3
+ export declare const AdminExtension: graphql.DocumentNode;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdminExtension = exports.ShopExtension = void 0;
4
+ const graphql_tag_1 = require("graphql-tag");
5
+ const base = (0, graphql_tag_1.gql) `
6
+ extend type Product {
7
+ badges: [Badge!]
8
+ }
9
+
10
+ # type SearchResultBadge {
11
+ # id: ID!
12
+ # name: String
13
+ # color: String!
14
+ # }
15
+
16
+ # extend type SearchResult {
17
+ # badges: [SearchResultBadge!]
18
+ # }
19
+
20
+ type BadgeTranslation {
21
+ id: ID!
22
+ createdAt: DateTime!
23
+ updatedAt: DateTime!
24
+
25
+ languageCode: LanguageCode!
26
+ name: String!
27
+ }
28
+
29
+ type Badge implements Node {
30
+ id: ID!
31
+ createdAt: DateTime!
32
+ updatedAt: DateTime!
33
+
34
+ product: Product!
35
+ color: String!
36
+ name: String
37
+ translations(languageCode: LanguageCode): [BadgeTranslation!]!
38
+ }
39
+ `;
40
+ exports.ShopExtension = (0, graphql_tag_1.gql) `
41
+ ${base}
42
+ `;
43
+ exports.AdminExtension = (0, graphql_tag_1.gql) `
44
+ ${base}
45
+
46
+ input BadgeTranslationInput {
47
+ languageCode: LanguageCode!
48
+ name: String!
49
+ }
50
+
51
+ input CreateBadgeInput {
52
+ productId: ID!
53
+ color: String!
54
+ translations: [BadgeTranslationInput!]
55
+ }
56
+
57
+ input RemoveBadgeInput {
58
+ id: ID!
59
+ }
60
+ input EditBadgeInput {
61
+ id: ID!
62
+ color: String
63
+ translations: [BadgeTranslationInput!]
64
+ }
65
+
66
+ extend type Mutation {
67
+ createBadge(input: CreateBadgeInput!): Badge!
68
+ editBadge(input: EditBadgeInput!): Badge!
69
+ removeBadge(input: RemoveBadgeInput!): Boolean!
70
+ }
71
+
72
+ input GetProductBadgesInput {
73
+ productId: ID!
74
+ }
75
+
76
+ extend type Query {
77
+ getProductBadges(input: GetProductBadgesInput!): [Badge!]
78
+ }
79
+ `;
@@ -0,0 +1,2 @@
1
+ export declare class BadgesServerPlugin {
2
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BadgesServerPlugin = void 0;
10
+ const core_1 = require("@deenruv/core");
11
+ const Badge_1 = require("./entities/Badge");
12
+ const BadgeTranslation_1 = require("./entities/BadgeTranslation");
13
+ const badge_extension_1 = require("./extensions/badge.extension");
14
+ const badge_admin_resolver_1 = require("./resolvers/badge-admin.resolver");
15
+ const badge_entity_resolver_1 = require("./resolvers/badge-entity.resolver");
16
+ const badge_service_1 = require("./services/badge.service");
17
+ let BadgesServerPlugin = class BadgesServerPlugin {
18
+ };
19
+ exports.BadgesServerPlugin = BadgesServerPlugin;
20
+ exports.BadgesServerPlugin = BadgesServerPlugin = __decorate([
21
+ (0, core_1.DeenruvPlugin)({
22
+ compatibility: "^0.0.20",
23
+ imports: [core_1.PluginCommonModule],
24
+ providers: [badge_service_1.BadgeService],
25
+ entities: [Badge_1.Badge, BadgeTranslation_1.BadgeTranslation],
26
+ adminApiExtensions: {
27
+ schema: badge_extension_1.AdminExtension,
28
+ resolvers: [badge_admin_resolver_1.BadgeAdminResolver],
29
+ },
30
+ shopApiExtensions: {
31
+ schema: badge_extension_1.ShopExtension,
32
+ resolvers: [badge_entity_resolver_1.BadgesResolver],
33
+ },
34
+ })
35
+ ], BadgesServerPlugin);
@@ -0,0 +1,19 @@
1
+ import type { RequestContext } from "@deenruv/core";
2
+ import { BadgeService } from "../services/badge.service.js";
3
+ import { ModelTypes } from "../zeus/index.js";
4
+ export declare class BadgeAdminResolver {
5
+ private badgeService;
6
+ constructor(badgeService: BadgeService);
7
+ createBadge(ctx: RequestContext, args: {
8
+ input: ModelTypes["CreateBadgeInput"];
9
+ }): Promise<false | import("../entities/Badge.js").Badge>;
10
+ removeBadge(ctx: RequestContext, args: {
11
+ input: ModelTypes["RemoveBadgeInput"];
12
+ }): Promise<boolean>;
13
+ editBadge(ctx: RequestContext, args: {
14
+ input: ModelTypes["EditBadgeInput"];
15
+ }): Promise<false | import("../entities/Badge.js").Badge>;
16
+ getProductBadges(ctx: RequestContext, args: {
17
+ input: ModelTypes["GetProductBadgesInput"];
18
+ }): Promise<import("@deenruv/core").Translated<import("../entities/Badge.js").Badge>[]>;
19
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BadgeAdminResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ const core_1 = require("@deenruv/core");
18
+ const graphql_2 = require("@nestjs/graphql");
19
+ const badge_service_js_1 = require("../services/badge.service.js");
20
+ let BadgeAdminResolver = class BadgeAdminResolver {
21
+ constructor(badgeService) {
22
+ this.badgeService = badgeService;
23
+ }
24
+ async createBadge(ctx, args) {
25
+ return this.badgeService.createBadge(ctx, args.input);
26
+ }
27
+ async removeBadge(ctx, args) {
28
+ return this.badgeService.removeBadge(ctx, args.input.id);
29
+ }
30
+ async editBadge(ctx, args) {
31
+ return this.badgeService.editBadge(ctx, args.input);
32
+ }
33
+ async getProductBadges(ctx, args) {
34
+ return this.badgeService.findAll(ctx, [args.input.productId]);
35
+ }
36
+ };
37
+ exports.BadgeAdminResolver = BadgeAdminResolver;
38
+ __decorate([
39
+ (0, graphql_2.Mutation)(),
40
+ (0, core_1.Transaction)(),
41
+ (0, core_1.Allow)(core_1.Permission.Authenticated),
42
+ __param(0, (0, core_1.Ctx)()),
43
+ __param(1, (0, graphql_2.Args)()),
44
+ __metadata("design:type", Function),
45
+ __metadata("design:paramtypes", [Function, Object]),
46
+ __metadata("design:returntype", Promise)
47
+ ], BadgeAdminResolver.prototype, "createBadge", null);
48
+ __decorate([
49
+ (0, graphql_2.Mutation)(),
50
+ (0, core_1.Transaction)(),
51
+ (0, core_1.Allow)(core_1.Permission.Authenticated),
52
+ __param(0, (0, core_1.Ctx)()),
53
+ __param(1, (0, graphql_2.Args)()),
54
+ __metadata("design:type", Function),
55
+ __metadata("design:paramtypes", [Function, Object]),
56
+ __metadata("design:returntype", Promise)
57
+ ], BadgeAdminResolver.prototype, "removeBadge", null);
58
+ __decorate([
59
+ (0, graphql_2.Mutation)(),
60
+ (0, core_1.Transaction)(),
61
+ (0, core_1.Allow)(core_1.Permission.Authenticated),
62
+ __param(0, (0, core_1.Ctx)()),
63
+ __param(1, (0, graphql_2.Args)()),
64
+ __metadata("design:type", Function),
65
+ __metadata("design:paramtypes", [Function, Object]),
66
+ __metadata("design:returntype", Promise)
67
+ ], BadgeAdminResolver.prototype, "editBadge", null);
68
+ __decorate([
69
+ (0, graphql_2.Query)(),
70
+ __param(0, (0, core_1.Ctx)()),
71
+ __param(1, (0, graphql_2.Args)()),
72
+ __metadata("design:type", Function),
73
+ __metadata("design:paramtypes", [Function, Object]),
74
+ __metadata("design:returntype", Promise)
75
+ ], BadgeAdminResolver.prototype, "getProductBadges", null);
76
+ exports.BadgeAdminResolver = BadgeAdminResolver = __decorate([
77
+ (0, graphql_1.Resolver)(),
78
+ __metadata("design:paramtypes", [badge_service_js_1.BadgeService])
79
+ ], BadgeAdminResolver);
@@ -0,0 +1,7 @@
1
+ import { Product, RequestContext } from "@deenruv/core";
2
+ import { BadgeService } from "../services/badge.service.js";
3
+ export declare class BadgesResolver {
4
+ private badgeService;
5
+ constructor(badgeService: BadgeService);
6
+ badges(ctx: RequestContext, parent: Product): Promise<import("@deenruv/core").Translated<import("../entities/Badge.js").Badge>[]>;
7
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BadgesResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ const core_1 = require("@deenruv/core");
18
+ const badge_service_js_1 = require("../services/badge.service.js");
19
+ let BadgesResolver = class BadgesResolver {
20
+ constructor(badgeService) {
21
+ this.badgeService = badgeService;
22
+ }
23
+ async badges(ctx, parent) {
24
+ return this.badgeService.findAll(ctx, [parent.id]);
25
+ }
26
+ };
27
+ exports.BadgesResolver = BadgesResolver;
28
+ __decorate([
29
+ (0, graphql_1.ResolveField)(),
30
+ __param(0, (0, core_1.Ctx)()),
31
+ __param(1, (0, graphql_1.Parent)()),
32
+ __metadata("design:type", Function),
33
+ __metadata("design:paramtypes", [core_1.RequestContext, core_1.Product]),
34
+ __metadata("design:returntype", Promise)
35
+ ], BadgesResolver.prototype, "badges", null);
36
+ exports.BadgesResolver = BadgesResolver = __decorate([
37
+ (0, graphql_1.Resolver)("Product"),
38
+ __metadata("design:paramtypes", [badge_service_js_1.BadgeService])
39
+ ], BadgesResolver);
@@ -0,0 +1,15 @@
1
+ import { TransactionalConnection, RequestContext, TranslatorService, TranslatableSaver, ID } from "@deenruv/core";
2
+ import { Badge } from "../entities/Badge";
3
+ import { ModelTypes } from "../zeus";
4
+ export declare class BadgeService {
5
+ private connection;
6
+ private translator;
7
+ private translatableSaver;
8
+ private readonly log;
9
+ constructor(connection: TransactionalConnection, translator: TranslatorService, translatableSaver: TranslatableSaver);
10
+ findOne(ctx: RequestContext, id: ID): Promise<Badge>;
11
+ findAll(ctx: RequestContext, productIds: ID[]): Promise<import("@deenruv/core").Translated<Badge>[]>;
12
+ createBadge(ctx: RequestContext, { productId, ...input }: ModelTypes["CreateBadgeInput"]): Promise<false | Badge>;
13
+ removeBadge(ctx: RequestContext, id: ID): Promise<boolean>;
14
+ editBadge(ctx: RequestContext, input: ModelTypes["EditBadgeInput"]): Promise<false | Badge>;
15
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.BadgeService = void 0;
24
+ const common_1 = require("@nestjs/common");
25
+ const typeorm_1 = require("typeorm");
26
+ const core_1 = require("@deenruv/core");
27
+ const Badge_1 = require("../entities/Badge");
28
+ const BadgeTranslation_1 = require("../entities/BadgeTranslation");
29
+ let BadgeService = class BadgeService {
30
+ constructor(connection, translator, translatableSaver) {
31
+ this.connection = connection;
32
+ this.translator = translator;
33
+ this.translatableSaver = translatableSaver;
34
+ this.log = (msg) => core_1.Logger.info(msg, "BadgeService");
35
+ this.log("BadgeService initialized");
36
+ }
37
+ async findOne(ctx, id) {
38
+ const badge = await this.connection
39
+ .getRepository(ctx, Badge_1.Badge)
40
+ .findOne({ where: { id } });
41
+ if (!badge)
42
+ throw new core_1.EntityNotFoundError("Badge not found", id);
43
+ return badge;
44
+ }
45
+ async findAll(ctx, productIds) {
46
+ const badges = await this.connection
47
+ .getRepository(ctx, Badge_1.Badge)
48
+ .find({ where: { product: { id: (0, typeorm_1.In)(productIds) } } });
49
+ return badges.map((el) => this.translator.translate(el, ctx));
50
+ }
51
+ async createBadge(ctx, _a) {
52
+ var { productId } = _a, input = __rest(_a, ["productId"]);
53
+ const product = await this.connection
54
+ .getRepository(ctx, core_1.Product)
55
+ .findOne({ where: { id: productId } });
56
+ if (!product)
57
+ throw new core_1.EntityNotFoundError("Product not found", productId);
58
+ try {
59
+ const badge = await this.translatableSaver.create({
60
+ ctx,
61
+ input: Object.assign({ product }, input),
62
+ entityType: Badge_1.Badge,
63
+ translationType: BadgeTranslation_1.BadgeTranslation,
64
+ });
65
+ return badge;
66
+ }
67
+ catch (err) {
68
+ const message = err instanceof Error ? err.message : "Unknown error";
69
+ this.log(`Error while creating badge: ${message}`);
70
+ return false;
71
+ }
72
+ }
73
+ async removeBadge(ctx, id) {
74
+ const badge = await this.findOne(ctx, id);
75
+ if (!badge)
76
+ throw new Error("Badge already removed.");
77
+ try {
78
+ await this.connection.getRepository(ctx, Badge_1.Badge).remove(badge);
79
+ return true;
80
+ }
81
+ catch (err) {
82
+ const message = err instanceof Error ? err.message : "Unknown error";
83
+ this.log(`Error while removing badge: ${message}`);
84
+ return false;
85
+ }
86
+ }
87
+ async editBadge(ctx, input) {
88
+ const badge = await this.findOne(ctx, input.id);
89
+ if (!badge)
90
+ throw new core_1.EntityNotFoundError("Badge not found", input.id);
91
+ try {
92
+ return await this.translatableSaver.update({
93
+ ctx,
94
+ input,
95
+ entityType: Badge_1.Badge,
96
+ translationType: BadgeTranslation_1.BadgeTranslation,
97
+ });
98
+ }
99
+ catch (err) {
100
+ const message = err instanceof Error ? err.message : "Unknown error";
101
+ this.log(`Error while editing badge: ${message}`);
102
+ return false;
103
+ }
104
+ }
105
+ };
106
+ exports.BadgeService = BadgeService;
107
+ exports.BadgeService = BadgeService = __decorate([
108
+ (0, common_1.Injectable)(),
109
+ __metadata("design:paramtypes", [core_1.TransactionalConnection,
110
+ core_1.TranslatorService,
111
+ core_1.TranslatableSaver])
112
+ ], BadgeService);
@@ -0,0 +1,11 @@
1
+ export type MetricResponse = {
2
+ orderId: string;
3
+ orderPlacedAt: string;
4
+ totalWithTax: number;
5
+ orderProducts: {
6
+ id: number;
7
+ name: string;
8
+ quantity: number;
9
+ }[];
10
+ overallQuantity: number;
11
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare const AllTypesProps: Record<string, any>;
2
+ export declare const ReturnTypes: Record<string, any>;
3
+ export declare const Ops: {
4
+ query: "Query";
5
+ mutation: "Mutation";
6
+ };