Skip to content

Commit

Permalink
add new categories
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasp committed Jan 15, 2025
1 parent b9fcede commit f7006dd
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Events } from "discord.js";
import dotenv from "dotenv";

// use .env without extension file if node_env is not defined otherwise use .env.${node_env}
Expand Down Expand Up @@ -101,6 +102,17 @@ export const categoryEmojiMap: {
Bounty: "WMBOUNTY",
Video: "WMVIDEO",
Paraverse: "WMPARAVERSE",
Tip: "WMTIP",
Wallet: "WMWALLET",
RWA: "WMRWA",
Rollup: "WMROLLUP",
Meme: "WMMEME",
Jam: "WMJAM",
Grant: "WMGRANT",
Events: "WMEVENTS",
DV: "WMDV",
DAO: "WMDAO",
Coretime: "WMCORETIME",
};

export const NEWSLETTER_CATEGORY_NAME = "Newsletter";
Expand Down
10 changes: 10 additions & 0 deletions data/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const findOrCreatePost = async (

const contentType = determinePostType(messageLink);

console.log("aaa contentType", contentType);

const user = await findOrCreateUser(message);

// Ensure all tags exist
Expand Down Expand Up @@ -585,8 +587,16 @@ export function determinePostType(
const channelNewsIds = JSON.parse(process.env.CHANNELS_NEWS || "[]");
const channelArticleIds = JSON.parse(process.env.CHANNELS_ARTICLES || "[]");

console.log(
"aaa determinePostType",
messageLink,
channelNewsIds,
channelArticleIds,
);

for (const channelId of channelNewsIds) {
if (messageLink.includes(channelId)) {
console.log("aaa determinePostType news");
return "news";
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"data-migration:add-content-type": "ts-node prisma/migrations/20240422153641_add_content_type/data-migration.ts",
"data-migration:test": "ts-node prisma/log-multiple-post-earnings.ts",
"migrate-roles": "ts-node prisma/migrate-roles.ts",
"update-categories": "ts-node prisma/update-categories.ts",
"postinstall": "pnpm prisma generate"
},
"simple-git-hooks": {
Expand Down
88 changes: 88 additions & 0 deletions prisma/update-categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//update the categories in the database from the config.ts file
import { PrismaClient } from "@prisma/client";
import * as config from "../config";
const prisma = new PrismaClient();

export async function updateCategories() {
const categories = Object.keys(config.categoryEmojiMap);
const dbCategories = await prisma.category.findMany();

//check if the categories are in the database
const categoriesInDb = dbCategories.map((category) => category.name);
const categoriesNotInDb = categories.filter(
(category) => !categoriesInDb.includes(category),
);

console.log(
`Found ${dbCategories.length} categories in the database: ${dbCategories
.map((category) => category.name)
.join(", ")}`,
);

//create the categories that are not in the database
const categoriesToCreate = categoriesNotInDb.map((category) => ({
name: category,
emoji: config.categoryEmojiMap[category],
}));

console.log(
`Creating ${categoriesToCreate.length} missing categories: ${categoriesToCreate
.map((category) => `${category.name}: (${category.emoji})`)
.join(", ")}`,
);

for (const name in config.categoryEmojiMap) {
try {
const emojiName = config.categoryEmojiMap[name];

// 1) Seed Emoji
const emoji = await prisma.emoji.upsert({
where: {
id: emojiName,
},
update: {},
create: {
id: emojiName,
name: emojiName,
},
});

// 2) Seed Category
const category = await prisma.category.upsert({
where: {
name: name,
},
update: {
name: name,
emojiId: emoji.id,
},
create: {
name: name,
emojiId: emoji.id,
},
});

// 3) Seed Category Rules
await prisma.categoryRule.upsert({
where: {
emojiId: emoji.id,
},
update: {},
create: {
categoryId: category.id,
emojiId: emoji.id,
},
});
} catch (e) {
console.log("error seeding category", name, e);
}
}

console.log("Categories updated successfully");
}

async function main() {
await updateCategories();
}

main();

0 comments on commit f7006dd

Please sign in to comment.