Browse Source

feat(server): Create base entity & switch to ID type for ids

Michael Bromley 7 years ago
parent
commit
7ce604ce73
32 changed files with 126 additions and 203 deletions
  1. 1 1
      server/src/api/administrator/administrator.api.graphql
  2. 2 2
      server/src/api/customer/customer.api.graphql
  3. 1 1
      server/src/api/product-option/product-option.api.graphql
  4. 1 1
      server/src/api/product/product.api.graphql
  5. 1 1
      server/src/common/common-types.graphql
  6. 5 0
      server/src/common/common-types.ts
  7. 5 12
      server/src/entity/address/address.entity.ts
  8. 1 1
      server/src/entity/address/address.graphql
  9. 5 20
      server/src/entity/administrator/administrator.entity.ts
  10. 1 1
      server/src/entity/administrator/administrator.graphql
  11. 21 0
      server/src/entity/base/base.entity.ts
  12. 5 21
      server/src/entity/customer/customer.entity.ts
  13. 1 1
      server/src/entity/customer/customer.graphql
  14. 5 8
      server/src/entity/product-option-group/product-option-group-translation.entity.ts
  15. 5 12
      server/src/entity/product-option-group/product-option-group.entity.ts
  16. 4 4
      server/src/entity/product-option-group/product-option-group.graphql
  17. 5 8
      server/src/entity/product-option/product-option-translation.entity.ts
  18. 6 21
      server/src/entity/product-option/product-option.entity.ts
  19. 3 3
      server/src/entity/product-option/product-option.graphql
  20. 5 8
      server/src/entity/product-variant/product-variant-translation.entity.ts
  21. 5 22
      server/src/entity/product-variant/product-variant.entity.ts
  22. 2 2
      server/src/entity/product-variant/product-variant.graphql
  23. 5 8
      server/src/entity/product/product-translation.entity.ts
  24. 6 22
      server/src/entity/product/product.entity.ts
  25. 4 4
      server/src/entity/product/product.graphql
  26. 8 9
      server/src/entity/user/user.entity.ts
  27. 1 1
      server/src/entity/user/user.graphql
  28. 4 2
      server/src/locale/locale-types.ts
  29. 2 2
      server/src/service/customer.service.ts
  30. 2 1
      server/src/service/product-option-group.service.ts
  31. 2 1
      server/src/service/product-option.service.ts
  32. 2 3
      server/src/service/product.service.ts

+ 1 - 1
server/src/api/administrator/administrator.api.graphql

@@ -1,6 +1,6 @@
 type Query {
   administrators: [Administrator]
-  administrator(id: String!): Administrator
+  administrator(id: ID!): Administrator
 }
 
 type Mutation {

+ 2 - 2
server/src/api/customer/customer.api.graphql

@@ -1,13 +1,13 @@
 type Query {
   customers(take: Int, skip: Int): CustomerList
-  customer(id: String!): Customer
+  customer(id: ID!): Customer
 }
 
 type Mutation {
   "Create a new Customer. If a password is provided, a new User will also be created an linked to the Customer."
   createCustomer(input: CreateCustomerInput!, password: String): Customer
   "Create a new Address and associate it with the Customer specified by customerId"
-  createCustomerAddress(customerId: String, input: CreateAddressInput): Address
+  createCustomerAddress(customerId: ID, input: CreateAddressInput): Address
 }
 
 type CustomerList implements PaginatedList {

+ 1 - 1
server/src/api/product-option/product-option.api.graphql

@@ -1,6 +1,6 @@
 type Query {
     productOptionGroups(languageCode: LanguageCode): [ProductOptionGroup]
-    productOptionGroup(id: String!, languageCode: LanguageCode): ProductOptionGroup
+    productOptionGroup(id: ID!, languageCode: LanguageCode): ProductOptionGroup
 }
 
 type Mutation {

+ 1 - 1
server/src/api/product/product.api.graphql

@@ -1,6 +1,6 @@
 type Query {
     products(languageCode: LanguageCode, take: Int, skip: Int): ProductList
-    product(id: String!, languageCode: LanguageCode): Product
+    product(id: ID!, languageCode: LanguageCode): Product
 }
 
 type Mutation {

+ 1 - 1
server/src/common/common-types.graphql

@@ -4,5 +4,5 @@ interface PaginatedList {
 }
 
 interface Node {
-    id: String!
+    id: ID!
 }

+ 5 - 0
server/src/common/common-types.ts

@@ -18,3 +18,8 @@ export type PaginatedList<T> = {
     items: T[];
     totalItems: number;
 };
+
+/**
+ * An entity ID
+ */
+export type ID = string | number;

+ 5 - 12
server/src/entity/address/address.entity.ts

@@ -1,17 +1,14 @@
-import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
+import { Column, Entity, ManyToOne } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
+import { VendureEntity } from '../base/base.entity';
 import { Customer } from '../customer/customer.entity';
 
-@Entity('address')
-export class Address {
+@Entity()
+export class Address extends VendureEntity {
     constructor(input?: DeepPartial<Address>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     @ManyToOne(type => Customer, customer => customer.addresses)
     customer: Customer;
 
@@ -36,8 +33,4 @@ export class Address {
     @Column() defaultShippingAddress: boolean;
 
     @Column() defaultBillingAddress: boolean;
-
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
 }

+ 1 - 1
server/src/entity/address/address.graphql

@@ -1,5 +1,5 @@
 type Address implements Node {
-  id: String!
+  id: ID!
   fullName: String
   company: String
   streetLine1: String

+ 5 - 20
server/src/entity/administrator/administrator.entity.ts

@@ -1,25 +1,14 @@
-import {
-    Column,
-    CreateDateColumn,
-    Entity,
-    JoinColumn,
-    OneToOne,
-    PrimaryGeneratedColumn,
-    UpdateDateColumn,
-} from 'typeorm';
+import { Column, Entity, JoinColumn, OneToOne } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
+import { VendureEntity } from '../base/base.entity';
 import { User } from '../user/user.entity';
 
-@Entity('administrator')
-export class Administrator {
+@Entity()
+export class Administrator extends VendureEntity {
     constructor(input?: DeepPartial<Administrator>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     @Column() firstName: string;
 
     @Column() lastName: string;
@@ -30,8 +19,4 @@ export class Administrator {
     @OneToOne(type => User, { eager: true })
     @JoinColumn()
     user: User;
-
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
 }

+ 1 - 1
server/src/entity/administrator/administrator.graphql

@@ -1,5 +1,5 @@
 type Administrator implements Node {
-    id: String!
+    id: ID!
     firstName: String
     lastName: String
     emailAddress: String

+ 21 - 0
server/src/entity/base/base.entity.ts

@@ -0,0 +1,21 @@
+import { CreateDateColumn, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
+import { DeepPartial, ID } from '../../common/common-types';
+
+/**
+ * This is the base class from which all entities inherit.
+ */
+export abstract class VendureEntity {
+    protected constructor(input?: DeepPartial<VendureEntity>) {
+        if (input) {
+            for (const [key, value] of Object.entries(input)) {
+                this[key] = value;
+            }
+        }
+    }
+
+    @PrimaryGeneratedColumn('increment') id: ID;
+
+    @CreateDateColumn() createdAt: string;
+
+    @UpdateDateColumn() updatedAt: string;
+}

+ 5 - 21
server/src/entity/customer/customer.entity.ts

@@ -1,27 +1,15 @@
-import {
-    Column,
-    CreateDateColumn,
-    Entity,
-    JoinColumn,
-    OneToMany,
-    OneToOne,
-    PrimaryGeneratedColumn,
-    UpdateDateColumn,
-} from 'typeorm';
+import { Column, Entity, JoinColumn, OneToMany, OneToOne } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
 import { Address } from '../address/address.entity';
+import { VendureEntity } from '../base/base.entity';
 import { User } from '../user/user.entity';
 
-@Entity('customer')
-export class Customer {
+@Entity()
+export class Customer extends VendureEntity {
     constructor(input?: DeepPartial<Customer>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     @Column() firstName: string;
 
     @Column() lastName: string;
@@ -37,8 +25,4 @@ export class Customer {
     @OneToOne(type => User, { eager: true })
     @JoinColumn()
     user?: User;
-
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
 }

+ 1 - 1
server/src/entity/customer/customer.graphql

@@ -1,5 +1,5 @@
 type Customer implements Node {
-  id: String!
+  id: ID!
   firstName: String
   lastName: String
   phoneNumber: String

+ 5 - 8
server/src/entity/product-option-group/product-option-group-translation.entity.ts

@@ -1,19 +1,16 @@
-import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
+import { Column, Entity, ManyToOne } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
 import { LanguageCode } from '../../locale/language-code';
 import { Translation } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { ProductOptionGroup } from './product-option-group.entity';
 
-@Entity('product_option_group_translation')
-export class ProductOptionGroupTranslation implements Translation<ProductOptionGroup> {
+@Entity()
+export class ProductOptionGroupTranslation extends VendureEntity implements Translation<ProductOptionGroup> {
     constructor(input?: DeepPartial<Translation<ProductOptionGroup>>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     @Column() languageCode: LanguageCode;
 
     @Column() name: string;

+ 5 - 12
server/src/entity/product-option-group/product-option-group.entity.ts

@@ -1,28 +1,21 @@
-import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
+import { Column, Entity, OneToMany } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
 import { LocaleString, Translatable, Translation } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { ProductOption } from '../product-option/product-option.entity';
 import { ProductOptionGroupTranslation } from './product-option-group-translation.entity';
 
-@Entity('product_option_group')
-export class ProductOptionGroup implements Translatable {
+@Entity()
+export class ProductOptionGroup extends VendureEntity implements Translatable {
     constructor(input?: DeepPartial<ProductOptionGroup>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     name: LocaleString;
 
     @Column({ unique: true })
     code: string;
 
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
-
     @OneToMany(type => ProductOptionGroupTranslation, translation => translation.base, { eager: true })
     translations: Array<Translation<ProductOptionGroup>>;
 

+ 4 - 4
server/src/entity/product-option-group/product-option-group.graphql

@@ -1,5 +1,5 @@
 type ProductOptionGroup implements Node {
-    id: String!
+    id: ID!
     languageCode: LanguageCode
     code: String
     name: String
@@ -8,13 +8,13 @@ type ProductOptionGroup implements Node {
 }
 
 type ProductOptionGroupTranslation {
-    id: String!
+    id: ID!
     languageCode: LanguageCode!
     name: String!
 }
 
 input ProductOptionGroupTranslationInput {
-    id: String
+    id: ID
     languageCode: LanguageCode!
     name: String!
 }
@@ -26,7 +26,7 @@ input CreateProductOptionGroupInput {
 }
 
 input UpdateProductOptionGroupInput {
-    id: String!
+    id: ID!
     code: String!
     translations: [ProductOptionGroupTranslationInput]!
 }

+ 5 - 8
server/src/entity/product-option/product-option-translation.entity.ts

@@ -1,19 +1,16 @@
-import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
+import { Column, Entity, ManyToOne } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
 import { LanguageCode } from '../../locale/language-code';
 import { Translation } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { ProductOption } from './product-option.entity';
 
-@Entity('product_option_translation')
-export class ProductOptionTranslation implements Translation<ProductOption> {
+@Entity()
+export class ProductOptionTranslation extends VendureEntity implements Translation<ProductOption> {
     constructor(input?: DeepPartial<Translation<ProductOption>>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     @Column() languageCode: LanguageCode;
 
     @Column() name: string;

+ 6 - 21
server/src/entity/product-option/product-option.entity.ts

@@ -1,35 +1,20 @@
-import {
-    Column,
-    CreateDateColumn,
-    Entity,
-    ManyToOne,
-    OneToMany,
-    PrimaryGeneratedColumn,
-    UpdateDateColumn,
-} from 'typeorm';
+import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
-import { LocaleString, Translatable, Translation, TranslationInput } from '../../locale/locale-types';
+import { LocaleString, Translatable, Translation } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { ProductOptionGroup } from '../product-option-group/product-option-group.entity';
 import { ProductOptionTranslation } from './product-option-translation.entity';
 
-@Entity('product_option')
-export class ProductOption implements Translatable {
+@Entity()
+export class ProductOption extends VendureEntity implements Translatable {
     constructor(input?: DeepPartial<ProductOption>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     name: LocaleString;
 
     @Column() code: string;
 
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
-
     @OneToMany(type => ProductOptionTranslation, translation => translation.base, { eager: true })
     translations: Array<Translation<ProductOption>>;
 

+ 3 - 3
server/src/entity/product-option/product-option.graphql

@@ -1,5 +1,5 @@
 type ProductOption implements Node {
-    id: String!
+    id: ID!
     languageCode: LanguageCode
     code: String
     name: String
@@ -7,13 +7,13 @@ type ProductOption implements Node {
 }
 
 type ProductOptionTranslation {
-    id: String!
+    id: ID!
     languageCode: LanguageCode!
     name: String!
 }
 
 input ProductOptionTranslationInput {
-    id: String
+    id: ID
     languageCode: LanguageCode!
     name: String!
 }

+ 5 - 8
server/src/entity/product-variant/product-variant-translation.entity.ts

@@ -1,19 +1,16 @@
-import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
+import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
 import { LanguageCode } from '../../locale/language-code';
 import { Translation } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { ProductVariant } from './product-variant.entity';
 
-@Entity('product_variant_translation')
-export class ProductVariantTranslation implements Translation<ProductVariant> {
+@Entity()
+export class ProductVariantTranslation extends VendureEntity implements Translation<ProductVariant> {
     constructor(input?: DeepPartial<Translation<ProductVariant>>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     @Column() languageCode: LanguageCode;
 
     @Column() name: string;

+ 5 - 22
server/src/entity/product-variant/product-variant.entity.ts

@@ -1,30 +1,17 @@
-import {
-    Column,
-    CreateDateColumn,
-    Entity,
-    JoinTable,
-    ManyToMany,
-    ManyToOne,
-    OneToMany,
-    PrimaryGeneratedColumn,
-    UpdateDateColumn,
-} from 'typeorm';
+import { Column, Entity, JoinTable, ManyToMany, ManyToOne, OneToMany } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
 import { LocaleString, Translatable, Translation } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { ProductOption } from '../product-option/product-option.entity';
 import { Product } from '../product/product.entity';
 import { ProductVariantTranslation } from './product-variant-translation.entity';
 
-@Entity('product_variant')
-export class ProductVariant implements Translatable {
+@Entity()
+export class ProductVariant extends VendureEntity implements Translatable {
     constructor(input?: DeepPartial<ProductVariant>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     name: LocaleString;
 
     @Column() sku: string;
@@ -33,10 +20,6 @@ export class ProductVariant implements Translatable {
 
     @Column() price: number;
 
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
-
     @OneToMany(type => ProductVariantTranslation, translation => translation.base, { eager: true })
     translations: Array<Translation<ProductVariant>>;
 

+ 2 - 2
server/src/entity/product-variant/product-variant.graphql

@@ -1,5 +1,5 @@
 type ProductVariant implements Node {
-    id: String!
+    id: ID!
     sku: String
     name: String
     image: String
@@ -9,7 +9,7 @@ type ProductVariant implements Node {
 }
 
 type ProductVariantTranslation {
-    id: String!
+    id: ID!
     languageCode: LanguageCode!
     name: String!
 }

+ 5 - 8
server/src/entity/product/product-translation.entity.ts

@@ -1,19 +1,16 @@
-import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
+import { Column, Entity, ManyToOne } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
 import { LanguageCode } from '../../locale/language-code';
 import { Translation, TranslationInput } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { Product } from './product.entity';
 
-@Entity('product_translation')
-export class ProductTranslation implements Translation<Product> {
+@Entity()
+export class ProductTranslation extends VendureEntity implements Translation<Product> {
     constructor(input?: DeepPartial<TranslationInput<Product>>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     @Column() languageCode: LanguageCode;
 
     @Column() name: string;

+ 6 - 22
server/src/entity/product/product.entity.ts

@@ -1,29 +1,17 @@
-import {
-    Column,
-    CreateDateColumn,
-    Entity,
-    JoinTable,
-    ManyToMany,
-    OneToMany,
-    PrimaryGeneratedColumn,
-    UpdateDateColumn,
-} from 'typeorm';
+import { Column, Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm';
 import { DeepPartial } from '../../common/common-types';
-import { LocaleString, Translatable, Translation, TranslationInput } from '../../locale/locale-types';
+import { LocaleString, Translatable, Translation } from '../../locale/locale-types';
+import { VendureEntity } from '../base/base.entity';
 import { ProductOptionGroup } from '../product-option-group/product-option-group.entity';
 import { ProductVariant } from '../product-variant/product-variant.entity';
 import { ProductTranslation } from './product-translation.entity';
 
-@Entity('product')
-export class Product implements Translatable {
+@Entity()
+export class Product extends VendureEntity implements Translatable {
     constructor(input?: DeepPartial<Product>) {
-        if (input) {
-            Object.assign(this, input);
-        }
+        super(input);
     }
 
-    @PrimaryGeneratedColumn('uuid') id: string;
-
     name: LocaleString;
 
     slug: LocaleString;
@@ -32,10 +20,6 @@ export class Product implements Translatable {
 
     @Column() image: string;
 
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
-
     @OneToMany(type => ProductTranslation, translation => translation.base, { eager: true })
     translations: Array<Translation<Product>>;
 

+ 4 - 4
server/src/entity/product/product.graphql

@@ -1,5 +1,5 @@
 type Product implements Node {
-    id: String!
+    id: ID!
     languageCode: LanguageCode
     name: String
     slug: String
@@ -11,7 +11,7 @@ type Product implements Node {
 }
 
 type ProductTranslation {
-    id: String!
+    id: ID!
     languageCode: LanguageCode!
     name: String!
     slug: String!
@@ -19,7 +19,7 @@ type ProductTranslation {
 }
 
 input ProductTranslationInput {
-    id: String
+    id: ID
     languageCode: LanguageCode!
     name: String!
     slug: String
@@ -34,7 +34,7 @@ input CreateProductInput {
 }
 
 input UpdateProductInput {
-    id: String!
+    id: ID!
     image: String
     translations: [ProductTranslationInput]!
     optionGroupCodes: [String]

+ 8 - 9
server/src/entity/user/user.entity.ts

@@ -1,10 +1,13 @@
-import { Column, CreateDateColumn, Entity, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
+import { Column, Entity } from 'typeorm';
 import { Role } from '../../auth/role';
-import { Address } from '../address/address.entity';
+import { DeepPartial } from '../../common/common-types';
+import { VendureEntity } from '../base/base.entity';
 
-@Entity('user')
-export class User {
-    @PrimaryGeneratedColumn('uuid') id: string;
+@Entity()
+export class User extends VendureEntity {
+    constructor(input?: DeepPartial<User>) {
+        super(input);
+    }
 
     @Column({ unique: true })
     identifier: string;
@@ -14,8 +17,4 @@ export class User {
     @Column('simple-array') roles: Role[];
 
     @Column() lastLogin: string;
-
-    @CreateDateColumn() createdAt: string;
-
-    @UpdateDateColumn() updatedAt: string;
 }

+ 1 - 1
server/src/entity/user/user.graphql

@@ -1,5 +1,5 @@
 type User implements Node {
-    id: String!
+    id: ID!
     identifier: String
     passwordHash: String
     roles: [String]

+ 4 - 2
server/src/locale/locale-types.ts

@@ -1,3 +1,5 @@
+import { ID } from '../common/common-types';
+import { VendureEntity } from '../entity/base/base.entity';
 import { LanguageCode } from './language-code';
 
 /**
@@ -23,7 +25,7 @@ export interface Translatable { translations: Array<Translation<any>>; }
 export type Translation<T> =
     // Translation must include the languageCode and a reference to the base Translatable entity it is associated with
     {
-        id: string;
+        id: ID;
         languageCode: LanguageCode;
         base: T;
     } &
@@ -33,7 +35,7 @@ export type Translation<T> =
 /**
  * This is the type of a translation object when provided as input to a create or update operation.
  */
-export type TranslationInput<T> = { [K in TranslatableKeys<T>]: string } & { id?: string; languageCode: LanguageCode };
+export type TranslationInput<T> = { [K in TranslatableKeys<T>]: string } & { id?: ID; languageCode: LanguageCode };
 
 /**
  * This interface defines the shape of a DTO used to create / update an entity which has one or more LocaleString

+ 2 - 2
server/src/service/customer.service.ts

@@ -3,7 +3,7 @@ import { InjectConnection } from '@nestjs/typeorm';
 import { Connection } from 'typeorm';
 import { PasswordService } from '../auth/password.service';
 import { Role } from '../auth/role';
-import { PaginatedList } from '../common/common-types';
+import { ID, PaginatedList } from '../common/common-types';
 import { CreateAddressDto } from '../entity/address/address.dto';
 import { Address } from '../entity/address/address.entity';
 import { CreateCustomerDto } from '../entity/customer/customer.dto';
@@ -28,7 +28,7 @@ export class CustomerService {
         return this.connection.manager.findOne(Customer, userId);
     }
 
-    findAddressesByCustomerId(customerId: string): Promise<Address[]> {
+    findAddressesByCustomerId(customerId: ID): Promise<Address[]> {
         return this.connection
             .getRepository(Address)
             .createQueryBuilder('address')

+ 2 - 1
server/src/service/product-option-group.service.ts

@@ -1,6 +1,7 @@
 import { Injectable } from '@nestjs/common';
 import { InjectConnection } from '@nestjs/typeorm';
 import { Connection } from 'typeorm';
+import { ID } from '../common/common-types';
 import { DEFAULT_LANGUAGE_CODE } from '../common/constants';
 import { ProductOptionGroupTranslation } from '../entity/product-option-group/product-option-group-translation.entity';
 import {
@@ -27,7 +28,7 @@ export class ProductOptionGroupService {
             .then(groups => groups.map(group => translateDeep(group, lang, ['options'])));
     }
 
-    findOne(id: string, lang: LanguageCode): Promise<ProductOptionGroup | undefined> {
+    findOne(id: ID, lang: LanguageCode): Promise<ProductOptionGroup | undefined> {
         return this.connection.manager
             .findOne(ProductOptionGroup, id, {
                 relations: ['options'],

+ 2 - 1
server/src/service/product-option.service.ts

@@ -1,6 +1,7 @@
 import { Injectable } from '@nestjs/common';
 import { InjectConnection } from '@nestjs/typeorm';
 import { Connection } from 'typeorm';
+import { ID } from '../common/common-types';
 import { DEFAULT_LANGUAGE_CODE } from '../common/constants';
 import { ProductOptionGroup } from '../entity/product-option-group/product-option-group.entity';
 import { ProductOptionTranslation } from '../entity/product-option/product-option-translation.entity';
@@ -21,7 +22,7 @@ export class ProductOptionService {
             .then(groups => groups.map(group => translateDeep(group, lang)));
     }
 
-    findOne(id: string, lang: LanguageCode): Promise<ProductOption | undefined> {
+    findOne(id: ID, lang: LanguageCode): Promise<ProductOption | undefined> {
         return this.connection.manager
             .findOne(ProductOption, id, {
                 relations: ['group'],

+ 2 - 3
server/src/service/product.service.ts

@@ -1,7 +1,7 @@
 import { Injectable } from '@nestjs/common';
 import { InjectConnection } from '@nestjs/typeorm';
 import { Connection } from 'typeorm';
-import { PaginatedList } from '../common/common-types';
+import { ID, PaginatedList } from '../common/common-types';
 import { DEFAULT_LANGUAGE_CODE } from '../common/constants';
 import { ProductOptionGroup } from '../entity/product-option-group/product-option-group.entity';
 import { ProductTranslation } from '../entity/product/product-translation.entity';
@@ -9,7 +9,6 @@ import { CreateProductDto, UpdateProductDto } from '../entity/product/product.dt
 import { Product } from '../entity/product/product.entity';
 import { LanguageCode } from '../locale/language-code';
 import { translateDeep } from '../locale/translate-entity';
-import { TranslationUpdater } from '../locale/translation-updater';
 import { TranslationUpdaterService } from '../locale/translation-updater.service';
 
 @Injectable()
@@ -39,7 +38,7 @@ export class ProductService {
             });
     }
 
-    findOne(productId: string, lang: LanguageCode): Promise<Product | undefined> {
+    findOne(productId: ID, lang: LanguageCode): Promise<Product | undefined> {
         const relations = ['variants', 'optionGroups', 'variants.options'];
 
         return this.connection.manager