Skip to content

Commit

Permalink
2.5.13 don't trample moa options on sync
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljonescodes committed Dec 27, 2023
1 parent 4efab86 commit 90d179a
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 258 deletions.
23 changes: 23 additions & 0 deletions src/database/migrations/1703700724000-SquareSyncUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class SquareSyncUpdate1703700724000 implements MigrationInterface {
name = 'SquareSyncUpdate1703700724000';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "modifier" ADD "synced" boolean`);
await queryRunner.query(`ALTER TABLE "modifier_list" ADD "synced" boolean`);
await queryRunner.query(`ALTER TABLE "variation" ADD "synced" boolean`);
await queryRunner.query(`ALTER TABLE "item" ADD "synced" boolean`);
await queryRunner.query(`ALTER TABLE "catalog_image" ADD "synced" boolean`);
await queryRunner.query(`ALTER TABLE "category" ADD "synced" boolean`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "category" DROP COLUMN "synced"`);
await queryRunner.query(`ALTER TABLE "catalog_image" DROP COLUMN "synced"`);
await queryRunner.query(`ALTER TABLE "item" DROP COLUMN "synced"`);
await queryRunner.query(`ALTER TABLE "variation" DROP COLUMN "synced"`);
await queryRunner.query(`ALTER TABLE "modifier_list" DROP COLUMN "synced"`);
await queryRunner.query(`ALTER TABLE "modifier" DROP COLUMN "synced"`);
}
}
5 changes: 5 additions & 0 deletions src/moa-square/entities/catalog-image.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ export class CatalogImageEntity extends BaseEntity {
@VersionColumn({ nullable: true })
version?: number;

/* Moa */

@Column({ nullable: true })
synced?: boolean;

/* Square */

@Exclude({ toPlainOnly: true })
Expand Down
3 changes: 3 additions & 0 deletions src/moa-square/entities/category.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class CategoryEntity extends BaseEntity {
@Column({ nullable: true, default: true })
moaEnabled?: boolean;

@Column({ nullable: true })
synced?: boolean;

/*
* Square
*/
Expand Down
3 changes: 3 additions & 0 deletions src/moa-square/entities/item.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class ItemEntity extends BaseEntity {
* Moa
*/

@Column({ nullable: true })
synced?: boolean;

@ApiProperty({ required: false, nullable: true })
@Column({ nullable: true, default: 0 })
moaOrdinal?: number;
Expand Down
5 changes: 5 additions & 0 deletions src/moa-square/entities/modifier-list.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export class ModifierListEntity extends BaseEntity {
@VersionColumn({ nullable: true })
version?: number;

/* Moa */

@Column({ nullable: true })
synced?: boolean;

/* Square */
@Exclude({ toPlainOnly: true })
@Column({ nullable: true, unique: false }) // TODO unique: true
Expand Down
3 changes: 3 additions & 0 deletions src/moa-square/entities/modifier.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class ModifierEntity extends BaseEntity {
@Column({ type: Number, nullable: true })
ordinal?: number | null;

@Column({ nullable: true })
synced?: boolean;

@Exclude({ toPlainOnly: true })
@Column({ nullable: true })
modifierListId?: string;
Expand Down
3 changes: 3 additions & 0 deletions src/moa-square/entities/variation.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class VariationEntity extends BaseEntity {
@Column({ nullable: true, default: true })
moaEnabled?: boolean;

@Column({ nullable: true })
synced?: boolean;

/*
* Square
*/
Expand Down
32 changes: 24 additions & 8 deletions src/moa-square/services/catalog-images.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,33 @@ export class CatalogImagesService extends EntityRepositoryService<CatalogImageEn
}
},
*/
async process(params: { catalogImage: CatalogObject; catalogId: string }) {
this.logger.verbose(this.process.name);
async squareSyncOrFail(params: {
catalogImage: CatalogObject;
catalogId: string;
}) {
this.logger.verbose(this.squareSyncOrFail.name);
const { catalogImage, catalogId } = params;
const image = this.create({
squareId: catalogImage.id,
name: catalogImage?.imageData?.name,
url: catalogImage?.imageData?.url,
caption: catalogImage?.imageData?.caption,
catalogId,

let image = await this.findOne({
where: { catalogId, squareId: catalogImage.id },
});

if (!image) {
image = this.create({
squareId: catalogImage.id,
name: catalogImage?.imageData?.name,
url: catalogImage?.imageData?.url,
caption: catalogImage?.imageData?.caption,
synced: true,
catalogId,
});
} else {
image.name = catalogImage?.imageData?.name;
image.url = catalogImage?.imageData?.url;
image.caption = catalogImage?.imageData?.caption;
image.synced = true;
}

this.logger.verbose(`returning image`);
return await this.save(image);
}
Expand Down
Loading

0 comments on commit 90d179a

Please sign in to comment.