Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
Update jobs model types
Browse files Browse the repository at this point in the history
  • Loading branch information
orzechdev committed May 27, 2020
1 parent ef92ffe commit 6a65b66
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
14 changes: 12 additions & 2 deletions src/@sdk/helpers/LocalStorageHandler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
Checkout_lines_variant_attributes,
Checkout_lines_variant_pricing,
Checkout_lines_variant_product,
} from "../../fragments/gqlTypes/Checkout";
} from "@sdk/fragments/gqlTypes/Checkout";
import { IQueuedJobs } from "@sdk/jobs/QueuedJobs";

export enum LocalStorageItems {
JOB_QUEUE_CHECKOUT = "job_queueCheckout",
Expand Down Expand Up @@ -124,7 +125,16 @@ export interface IOrderModel {
number?: string | null;
}

export type IJobsModel = Record<string, Record<string, boolean>>;
export type IJobsGroupModel<G extends keyof IQueuedJobs> = Record<
keyof IQueuedJobs[G],
boolean
>;

type IQueuedJobsState<T> = {
[P in keyof T]?: Partial<Record<keyof T[P], boolean>>;
};

export type IJobsModel = IQueuedJobsState<IQueuedJobs>;

export interface ILocalStorageHandler {
getCheckout(): ICheckoutModel | null;
Expand Down
30 changes: 17 additions & 13 deletions src/@sdk/jobs/JobsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class JobsManager {
const jobGroupString = jobGroup.toString();
const jobNameString = jobName.toString();

const jobGroupObject = jobs ? jobs[jobGroupString] : null;
const jobGroupObject = jobs ? jobs[jobGroup] : null;

this.localStorageHandler.setJobs({
...jobs,
Expand All @@ -169,18 +169,22 @@ export class JobsManager {

if (jobs) {
Object.keys(jobs).forEach(jobGroupString => {
const jobGroup = jobs[jobGroupString];

Object.keys(jobGroup).forEach(jobNameString => {
const jobNameState = jobGroup[jobNameString];

if (jobNameState) {
this.addToQueue(
jobGroupString as keyof IQueuedJobs,
jobNameString as keyof QueuedJobs[keyof IQueuedJobs]
);
}
});
const jobGroupKey = jobGroupString as keyof IQueuedJobs;
const jobGroup = jobs[jobGroupKey];

if (jobGroup) {
Object.keys(jobGroup).forEach(jobNameString => {
const jobNameKey = jobNameString as keyof QueuedJobs[keyof IQueuedJobs];
const jobNameState = jobGroup[jobNameKey];

if (jobNameState) {
this.addToQueue(
jobGroupString as keyof IQueuedJobs,
jobNameString as keyof QueuedJobs[keyof IQueuedJobs]
);
}
});
}
});
}
}
Expand Down

0 comments on commit 6a65b66

Please sign in to comment.