Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product quiz TS migration #116

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
3 changes: 1 addition & 2 deletions shopify/product-quiz-template/.ignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Shopify
extensions/**/dist
shopify.app.**.toml
extensions/**/dist
29 changes: 0 additions & 29 deletions shopify/product-quiz-template/api/actions/scheduledShopifySync.js

This file was deleted.

28 changes: 0 additions & 28 deletions shopify/product-quiz-template/api/models/answer/actions/create.js

This file was deleted.

23 changes: 23 additions & 0 deletions shopify/product-quiz-template/api/models/answer/actions/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
applyParams,
save,
ActionOptions,
preventCrossShopDataAccess,
} from "gadget-server";

export const run: ActionRun = async ({
params,
record,
connections,
logger,
api,
}) => {
applyParams(params, record);
await preventCrossShopDataAccess(params, record);
await save(record);
};

export const options: ActionOptions = {
actionType: "create",
triggers: { api: true },
};
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
deleteRecord,
ActionOptions,
DeleteAnswerActionContext,
preventCrossShopDataAccess,
} from "gadget-server";

/**
* @param { DeleteAnswerActionContext } context
*/
export async function run({ params, record, logger, api }) {
export const run: ActionRun = async ({ params, record, logger, api }) => {
await preventCrossShopDataAccess(params, record);
await deleteRecord(record);
}
};

/**
* @param { DeleteAnswerActionContext } context
*/
export async function onSuccess({ params, record, logger, api }) {
export const onSuccess: ActionOnSuccess = async ({
params,
record,
logger,
api,
}) => {
// clean up recommended product
const recommendation = await api.recommendedProduct.findFirst({
filter: {
Expand All @@ -28,10 +28,9 @@ export async function onSuccess({ params, record, logger, api }) {
});

await api.recommendedProduct.delete(recommendation.id);
}
};

/** @type { ActionOptions } */
export const options = {
export const options: ActionOptions = {
actionType: "delete",
triggers: { api: true },
};
22 changes: 0 additions & 22 deletions shopify/product-quiz-template/api/models/answer/actions/update.js

This file was deleted.

17 changes: 17 additions & 0 deletions shopify/product-quiz-template/api/models/answer/actions/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
ActionOptions,
applyParams,
preventCrossShopDataAccess,
save,
} from "gadget-server";

export const run: ActionRun = async ({ params, record, logger, api }) => {
applyParams(params, record);
await preventCrossShopDataAccess(params, record);
await save(record);
};

export const options: ActionOptions = {
actionType: "update",
triggers: { api: true },
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
applyParams,
save,
ActionOptions,
preventCrossShopDataAccess,
} from "gadget-server";

export const run: ActionRun = async ({
params,
record,
connections,
logger,
api,
}) => {
applyParams(params, record);
await preventCrossShopDataAccess(params, record);
await save(record);
};

export const options: ActionOptions = {
actionType: "create",
triggers: { api: true },
};
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
deleteRecord,
ActionOptions,
DeleteQuestionActionContext,
preventCrossShopDataAccess,
} from "gadget-server";

/**
* @param { DeleteQuestionActionContext } context
*/
export async function run({ params, record, logger, api }) {
export const run: ActionRun = async ({ params, record, logger, api }) => {
await preventCrossShopDataAccess(params, record);
await deleteRecord(record);
}
};

/**
* @param { DeleteQuestionActionContext } context
*/
export async function onSuccess({ params, record, logger, api }) {
export const onSuccess: ActionOnSuccess = async ({
params,
record,
logger,
api,
}) => {
// clean up quiz answers
const answers = await api.answer.findMany({
filter: {
Expand All @@ -29,10 +29,9 @@ export async function onSuccess({ params, record, logger, api }) {

const ids = answers.map((answer) => answer.id);
await api.answer.bulkDelete(ids);
}
};

/** @type { ActionOptions } */
export const options = {
export const options: ActionOptions = {
actionType: "delete",
triggers: { api: true },
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
ActionOptions,
applyParams,
preventCrossShopDataAccess,
save,
} from "gadget-server";

export const run: ActionRun = async ({ params, record, logger, api }) => {
applyParams(params, record);
await preventCrossShopDataAccess(params, record);
await save(record);
};

export const options: ActionOptions = {
actionType: "update",
triggers: { api: true },
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ import {
applyParams,
save,
ActionOptions,
CreateQuizActionContext,
preventCrossShopDataAccess,
} from "gadget-server";

/**
* @param { CreateQuizActionContext } context
*/
export async function run({ params, record, connections, logger, api }) {
export const run: ActionRun = async ({
params,
record,
connections,
logger,
api,
}) => {
applyParams(params, record);
await preventCrossShopDataAccess(params, record);

record.slug = generateSlug(record.title);
record.shop = { _link: connections.shopify.currentShopId };

await save(record);
}
};

function generateSlug(input) {
function generateSlug(input: string) {
return (
input
// Convert to lowercase
Expand All @@ -33,13 +36,7 @@ function generateSlug(input) {
);
}

/**
* @param { CreateQuizActionContext } context
*/
export async function onSuccess({ params, record, logger, api }) {}

/** @type { ActionOptions } */
export const options = {
export const options: ActionOptions = {
actionType: "create",
triggers: { api: true },
};
Loading