Skip to content

Commit

Permalink
feat: added imagewidget and linkWidget (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: yuhur <[email protected]>
  • Loading branch information
YuraGB and yuhur authored Mar 27, 2024
1 parent 75609a1 commit cb5a340
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 12 deletions.
23 changes: 23 additions & 0 deletions src/db/schemas/imageWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { integer, pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
import { PagesTable } from "./page";
import { type InferSelectModel, relations } from "drizzle-orm";

export const ImageWidget = pgTable("image_widget", {
id: serial("id").primaryKey(),
title: text("title").notNull().default(""),
type: text("image_widget").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
image_link: text("image_link").notNull(),
image_title: text("image_title").notNull(),
link_title: text("image_src").notNull(),
pageId: integer("page_id").references(() => PagesTable.id),
});

export const ImageWidgetRelations = relations(ImageWidget, ({ one }) => ({
page: one(PagesTable, {
fields: [ImageWidget.pageId],
references: [PagesTable.id],
}),
}));

export type TImageWidgetSchema = InferSelectModel<typeof ImageWidget>;
22 changes: 22 additions & 0 deletions src/db/schemas/linkWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { integer, pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
import { PagesTable } from "./page";
import { type InferSelectModel, relations } from "drizzle-orm";

export const LinkWidget = pgTable("link_widget", {
id: serial("id").primaryKey(),
title: text("title").notNull().default(""),
type: text("link_widget").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
link_url: text("link_url").notNull(),
link_title: text("link_title").notNull(),
pageId: integer("page_id").references(() => PagesTable.id),
});

export const LinkWidgetRelations = relations(LinkWidget, ({ one }) => ({
page: one(PagesTable, {
fields: [LinkWidget.pageId],
references: [PagesTable.id],
}),
}));

export type TLinkWidgetSchema = InferSelectModel<typeof LinkWidget>;
6 changes: 5 additions & 1 deletion src/db/schemas/page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { integer, pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
import { UsersTable } from "./user";
import { type InferSelectModel, relations } from "drizzle-orm";
import { YoutubeWidget } from "./widget";
import { YoutubeWidget } from "./youtubeWidget";
import { LinkWidget } from "./linkWidget";
import { ImageWidget } from "./imageWidget";

export const PagesTable = pgTable("page", {
id: serial("id").primaryKey().unique(),
Expand All @@ -16,6 +18,8 @@ export const pageRelations = relations(PagesTable, ({ one, many }) => ({
references: [UsersTable.id],
}),
youtubeWidgets: many(YoutubeWidget),
linkWidgets: many(LinkWidget),
imageWidgets: many(ImageWidget),
}));

export type TPageSchema = InferSelectModel<typeof PagesTable>;
File renamed without changes.
8 changes: 4 additions & 4 deletions src/model/page/getPagesByUserId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as PagesSchema from "../../db/schemas/page";
import { eq } from "drizzle-orm";
import { drizzle } from "drizzle-orm/postgres-js";
import * as userSchema from "../../db/schemas/user";
import * as YoutubeSchema from "../../db/schemas/widget";
import * as YoutubeSchema from "../../db/schemas/youtubeWidget";
import postgres from "postgres";
import { type TPageSchema } from "../../db/schemas/page";

Expand Down Expand Up @@ -31,6 +31,6 @@ export const getPagesByUserId = async (
}
};

export type TPageDataResponse =
| Array<TPageSchema & { youtubeWidgets: YoutubeSchema.TYoutubeWidgetSchema[] }>
| null;
export type TPageDataResponse = Array<
TPageSchema & { youtubeWidgets: YoutubeSchema.TYoutubeWidgetSchema[] }
> | null;
2 changes: 1 addition & 1 deletion src/model/widget/createYoutubeWidget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { YoutubeWidget } from "../../db/schemas/widget";
import { YoutubeWidget } from "../../db/schemas/youtubeWidget";
import { db } from "../../db/db";
import { type TYoutubeWidget } from "../../routes/customPagesController/customePageCreate/types";

Expand Down
2 changes: 1 addition & 1 deletion src/model/widget/getWidgetById.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type TWidget } from "../../routes/customPagesController/customePageCreate/types";
import { db } from "../../db/db";
import { YoutubeWidget } from "../../db/schemas/widget";
import { YoutubeWidget } from "../../db/schemas/youtubeWidget";
import { eq } from "drizzle-orm";

export const getWidgetById = async (
Expand Down
2 changes: 1 addition & 1 deletion src/model/widget/getWidgetsByPageId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { YoutubeWidget } from "../../db/schemas/widget";
import { YoutubeWidget } from "../../db/schemas/youtubeWidget";
import { eq } from "drizzle-orm";
import { db } from "../../db/db";

Expand Down
2 changes: 1 addition & 1 deletion src/model/widget/removeWidget.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { db } from "../../db/db";
import { YoutubeWidget } from "../../db/schemas/widget";
import { YoutubeWidget } from "../../db/schemas/youtubeWidget";
import { eq } from "drizzle-orm";

interface TRemoveWidgetResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/model/widget/removeYoutubeWidgetById.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { db } from "../../db/db";
import { YoutubeWidget } from "../../db/schemas/widget";
import { YoutubeWidget } from "../../db/schemas/youtubeWidget";
import { eq } from "drizzle-orm";

interface TRemoveWidgetResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/model/widget/youtubeWidgetUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { YoutubeWidget } from "../../db/schemas/widget";
import { YoutubeWidget } from "../../db/schemas/youtubeWidget";
import { db } from "../../db/db";
import { type TYoutubeWidget } from "../../routes/customPagesController/customePageCreate/types";

Expand Down
2 changes: 1 addition & 1 deletion src/services/widgetService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { createYoutubeWidget } from "../../model/widget/createYoutubeWidget";
import { getWidgetById } from "../../model/widget/getWidgetById";
import { type IWidgetService } from "./types";
import { type TYoutubeWidgetSchema } from "../../db/schemas/widget";
import { type TYoutubeWidgetSchema } from "../../db/schemas/youtubeWidget";
import { youtubeWidgetUpdate } from "../../model/widget/youtubeWidgetUpdate";
import { removeYoutubeWidgetById } from "../../model/widget/removeYoutubeWidgetById";

Expand Down

0 comments on commit cb5a340

Please sign in to comment.