Skip to content

Commit

Permalink
fix: 🐛 order creation not working with templateId
Browse files Browse the repository at this point in the history
  • Loading branch information
SophiaH67 committed Apr 15, 2024
1 parent 5284c84 commit 8784076
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
18 changes: 4 additions & 14 deletions src/PrintOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,8 @@ export class PrintOne {
* Create an order
*/
public async createOrder(data: CreateOrder): Promise<Order> {
let templateId: undefined | string;

if (data.template instanceof Template) {
templateId = data.template.id;
} else {
templateId = data.template;
}
const template = data.templateId ?? data.template;
const templateId = template instanceof Template ? template.id : template;

const sendDateStr =
data.sendDate instanceof Date
Expand All @@ -272,13 +267,8 @@ export class PrintOne {
}

public async createCsvOrder(data: CreateCsvOrder): Promise<CsvOrder> {
let templateId: undefined | string;

if (data.template instanceof Template) {
templateId = data.template.id;
} else {
templateId = data.template;
}
const template = data.templateId ?? data.template;
const templateId = template instanceof Template ? template.id : template;

const formData = new FormData();
formData.append(
Expand Down
12 changes: 10 additions & 2 deletions src/models/CsvOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ export type CreateCsvOrder = {
recipient: Address;
mergeVariables?: Record<string, string>;
};
template: Template | string;
finish?: Finish;
billingId?: string;
sender?: Address;
};
} & (
| {
template: Template | string;
templateId: undefined;
}
| {
template: undefined;
templateId: string;
}
);

export class CsvOrder {
private _data: ICsvOrder;
Expand Down
12 changes: 10 additions & 2 deletions src/models/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ import { sleep } from "../utils";
export type CreateOrder = {
recipient: Address;
sender?: Address;
template: Template | string;
/**
* @default GLOSSY
*/
finish?: Finish;
mergeVariables?: Record<string, unknown>;
billingId?: string;
sendDate?: Date | string;
};
} & (
| {
template: Template | string;
templateId: undefined;
}
| {
template: undefined;
templateId: string;
}
);

export class Order {
private _data: IOrder;
Expand Down

0 comments on commit 8784076

Please sign in to comment.