Skip to content

Commit e3c2091

Browse files
committed
Updated featured widget; Marked tags page not used; Migration exception added
1 parent 13a60da commit e3c2091

14 files changed

Lines changed: 32 additions & 235 deletions

File tree

38.8 MB
Binary file not shown.

apps/web/.migrations/23-03-25_12-48-migrate-customers-to-memberships.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ const createMembership = async (domain, userId, courseId, paymentPlan) => {
178178

179179
const existingMembership = await Membership.findOne(payload);
180180
if (!existingMembership) {
181-
await Membership.create(payload);
181+
try {
182+
await Membership.create(payload);
183+
} catch (error) {
184+
console.log("Error creating membership for ", domain, error);
185+
}
182186
}
183187
};
184188

apps/web/graphql/courses/query.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -207,49 +207,4 @@ export default {
207207
status,
208208
}),
209209
},
210-
getCourses: {
211-
type: new GraphQLList(types.publicCoursesType),
212-
args: {
213-
offset: {
214-
type: GraphQLInt,
215-
},
216-
ids: {
217-
type: new GraphQLList(GraphQLString),
218-
},
219-
tag: {
220-
type: GraphQLString,
221-
},
222-
filterBy: {
223-
type: new GraphQLList(courseFilters),
224-
},
225-
},
226-
resolve: (
227-
_: any,
228-
{
229-
offset,
230-
ids,
231-
tag,
232-
filterBy,
233-
}: {
234-
offset?: number;
235-
ids?: string[];
236-
tag?: string;
237-
filterBy?: Filter[];
238-
},
239-
ctx: GQLContext,
240-
) => getCourses({ offset, ids, tag, filterBy, ctx }),
241-
},
242-
// getEnrolledCourses: {
243-
// type: new GraphQLList(types.enrolledCourses),
244-
// args: {
245-
// userId: {
246-
// type: new GraphQLNonNull(GraphQLString),
247-
// },
248-
// },
249-
// resolve: (
250-
// _: any,
251-
// { userId }: { userId: string },
252-
// context: GQLContext,
253-
// ) => getEnrolledCourses(userId, context),
254-
// },
255210
};

apps/web/pages/blog/index.tsx.notused

Lines changed: 0 additions & 83 deletions
This file was deleted.

apps/web/pages/courses.tsx.notused

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import {
22
HEADER_BLOG_POSTS_SECTION,
33
HEADER_TAG_SECTION,
4-
} from "../../ui-config/strings";
4+
} from "@/ui-config/strings";
55
import { FetchBuilder } from "@courselit/utils";
66
import { getBackendAddress, getPage } from "../../ui-lib/utils";
77
import dynamic from "next/dynamic";
88
import { Course, Page } from "@courselit/common-models";
99
import { useRouter } from "next/router";
10-
import BaseLayout from "../../components/public/base-layout";
10+
import BaseLayout from "@/components/public/base-layout";
1111

12-
const Items = dynamic(() => import("../../components/public/items"));
12+
const Items = dynamic(() => import("@/components/public/items"));
1313

1414
const generateQuery =
1515
(tag: string) =>
1616
(pageOffset = 1) =>
1717
`
1818
query {
19-
courses: getCourses(offset: ${pageOffset}, tag: "${tag}") {
19+
courses: getProducts(offset: ${pageOffset}, tag: "${tag}") {
2020
id,
2121
title,
2222
description,
@@ -62,7 +62,7 @@ function Posts(props: PostsProps) {
6262
);
6363
}
6464

65-
const getCourses = async (backend: string, tag: string) => {
65+
const getProducts= async (backend: string, tag: string) => {
6666
let courses = [];
6767
try {
6868
const fetch = new FetchBuilder()
@@ -79,7 +79,7 @@ const getCourses = async (backend: string, tag: string) => {
7979
export async function getServerSideProps({ query, req }: any) {
8080
const address = getBackendAddress(req.headers);
8181
const page = await getPage(address);
82-
const courses = await getCourses(getBackendAddress(req.headers), query.tag);
82+
const courses = await getProducts(getBackendAddress(req.headers), query.tag);
8383
return { props: { courses, page } };
8484
}
8585

docs/widgets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ You will get a unique `widgetId` from the framework. You have to use this as a k
116116
```js
117117
// Fetches courses with a certain tag
118118
Widget.getData = (id: string, settings: Record<string, unknown>) => `
119-
${id}: getCourses(offset: 1, tag: "${settings && settings.tag}") {
119+
${id}: getProducts(offset: 1, tag: "${settings && settings.tag}") {
120120
id,
121121
title,
122122
cost,

packages/common-widgets/src/featured/admin-widget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export default function AdminWidget({
104104

105105
const loadPublishedProducts = async () => {
106106
const query = `
107-
query {
108-
products: getCourses(offset: 1, filterBy: [COURSE, DOWNLOAD]) {
107+
query($limit: Int, $publicView: Boolean, $filter: [CourseFilters]) {
108+
products: getProducts(limit: $limit, filterBy: $filter, publicView: $publicView) {
109109
title,
110110
courseId,
111111
type
@@ -114,7 +114,7 @@ export default function AdminWidget({
114114
`;
115115
const fetch = new FetchBuilder()
116116
.setUrl(`${address.backend}/api/graph`)
117-
.setPayload(query)
117+
.setPayload({ query, variables: { limit: 1000, publicView: true, filter: ["COURSE", "DOWNLOAD"] } })
118118
.setIsGraphQLEndpoint(true)
119119
.build();
120120
try {

packages/common-widgets/src/featured/widget.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export default function Widget({
4444
}, [products]);
4545

4646
const loadCourses = async () => {
47-
const productsArgs = getGraphQLQueryStringFromObject(products);
47+
// const productsArgs = getGraphQLQueryStringFromObject(products);
4848
const query = `
49-
query {
50-
product: getProducts(ids: ${productsArgs}, limit: 1000, publicView: true) {
49+
query ($ids: [String]) {
50+
products: getProducts(ids: $ids, limit: 1000, publicView: true) {
5151
title
5252
courseId
5353
featuredImage {
@@ -78,15 +78,20 @@ export default function Widget({
7878
`;
7979
const fetch = new FetchBuilder()
8080
.setUrl(`${state.address.backend}/api/graph`)
81-
.setPayload(query)
81+
.setPayload({
82+
query,
83+
variables: {
84+
ids: products,
85+
},
86+
})
8287
.setIsGraphQLEndpoint(true)
8388
.build();
8489

8590
try {
8691
dispatch(actionCreators.networkAction(true));
8792
const response = await fetch.exec();
88-
if (response.product) {
89-
setProductItems(response.product);
93+
if (response.products) {
94+
setProductItems(response.products);
9095
}
9196
} catch (err) {
9297
console.log("Error", err.message); // eslint-disable-line no-console
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
declare module "next/link";
22
declare module "next/legacy/image";
3-
declare module "next/image";
43
declare module "next/navigation";

0 commit comments

Comments
 (0)