Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57fdf8e18e | |||
| 0cef1b671e | |||
| c17ecaaa7a | |||
| 69b7f1f864 | |||
| 2c8f09a028 | |||
| 184eafde46 |
@@ -1 +1,6 @@
|
||||
approvedGitRepositories:
|
||||
- "**"
|
||||
|
||||
enableScripts: true
|
||||
|
||||
nodeLinker: node-modules
|
||||
|
||||
+21
-21
@@ -12,48 +12,48 @@
|
||||
"prisma-update": "yarn prisma db push"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chakra-ui/charts": "^3.34.0",
|
||||
"@chakra-ui/react": "^3.34.0",
|
||||
"@chakra-ui/charts": "^3.35.0",
|
||||
"@chakra-ui/react": "^3.35.0",
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@escape.tech/graphql-armor": "^3.2.0",
|
||||
"@prisma/client": "^6.19.2",
|
||||
"@prisma/client": "^6.19.3",
|
||||
"@prisma/extension-accelerate": "^3.0.1",
|
||||
"@urql/next": "^2.0.0",
|
||||
"dotenv": "^17.3.1",
|
||||
"graphql": "^16.13.1",
|
||||
"dotenv": "^17.4.2",
|
||||
"graphql": "^16.13.2",
|
||||
"graphql-scalars": "^1.25.0",
|
||||
"graphql-yoga": "^5.18.1",
|
||||
"next": "16.2.1",
|
||||
"graphql-yoga": "^5.21.0",
|
||||
"next": "16.2.4",
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "19.2.4",
|
||||
"react-dom": "19.2.4",
|
||||
"react": "19.2.5",
|
||||
"react-dom": "19.2.5",
|
||||
"react-icons": "^5.6.0",
|
||||
"recharts": "^3.8.0",
|
||||
"recharts": "^3.8.1",
|
||||
"rxjs": "^7.8.2",
|
||||
"urql": "^5.0.1"
|
||||
"urql": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.3.5",
|
||||
"@eslint/js": "^9.39.4",
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@iconify/react": "^6.0.2",
|
||||
"@types/node": "^25.5.0",
|
||||
"@types/node": "^25.6.0",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
||||
"@typescript-eslint/parser": "^8.57.1",
|
||||
"baseline-browser-mapping": "^2.10.10",
|
||||
"@typescript-eslint/eslint-plugin": "^8.59.1",
|
||||
"@typescript-eslint/parser": "^8.59.1",
|
||||
"baseline-browser-mapping": "^2.10.25",
|
||||
"eslint": "^9.39.4",
|
||||
"eslint-config-next": "16.2.1",
|
||||
"eslint-config-next": "16.2.4",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-jsx-a11y": "^6.10.2",
|
||||
"eslint-plugin-prettier": "^5.5.5",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"prettier": "3.8.1",
|
||||
"prisma": "^6.19.2",
|
||||
"prettier": "3.8.3",
|
||||
"prisma": "^6.19.3",
|
||||
"tsx": "^4.21.0",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.57.1"
|
||||
"typescript-eslint": "^8.59.1"
|
||||
},
|
||||
"packageManager": "yarn@4.12.0"
|
||||
"packageManager": "yarn@4.14.1"
|
||||
}
|
||||
|
||||
+83
-11
@@ -39,6 +39,9 @@ export const resolvers = {
|
||||
const { startDate, endDate } = data;
|
||||
|
||||
if (!startDate || !endDate) {
|
||||
console.info(
|
||||
"GET STATS RANGE: REFUSED - one or both dates not provided."
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -79,29 +82,44 @@ export const resolvers = {
|
||||
) => {
|
||||
const { mutationKey } = data;
|
||||
|
||||
// If env is not development check for the mutation key.
|
||||
if (env !== "development") {
|
||||
// If mutation key was not provided.
|
||||
if (!mutationKey) {
|
||||
console.info("INIT: REFUSED - no mutation key was provided.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// If provided mutation key is invalid.
|
||||
if (mutationKey !== envMutationKey) {
|
||||
console.info("INIT: REFUSED - mutation key provided was incorrect.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const date = new Date().toISOString();
|
||||
let count = 0;
|
||||
const createdAtDate = new Date().toISOString();
|
||||
// How many tables were created
|
||||
let newTablesCount = 0;
|
||||
|
||||
// Check for daily stats document count.
|
||||
if ((await prisma.dailyStats.count()) === 0) {
|
||||
await prisma.dailyStats.create({ data: { createdAt: date } });
|
||||
count++;
|
||||
// Make a daily stats document.
|
||||
console.info("INIT: created new document");
|
||||
await prisma.dailyStats.create({ data: { createdAt: createdAtDate } });
|
||||
newTablesCount++;
|
||||
}
|
||||
// Check for a total stats document.
|
||||
if ((await prisma.totalStats.count()) === 0) {
|
||||
await prisma.totalStats.create({ data: { createdAt: date } });
|
||||
count++;
|
||||
// Make the total stats document.
|
||||
console.info("INIT: created new document");
|
||||
await prisma.totalStats.create({ data: { createdAt: createdAtDate } });
|
||||
newTablesCount++;
|
||||
}
|
||||
|
||||
return `${count} tables have been initialized with data.`;
|
||||
console.info(
|
||||
`INIT: ${newTablesCount} tables have been initialized with data.`
|
||||
);
|
||||
return `${newTablesCount} tables have been initialized with data.`;
|
||||
},
|
||||
cronJob: async (
|
||||
_parent: unknown,
|
||||
@@ -110,30 +128,42 @@ export const resolvers = {
|
||||
) => {
|
||||
const { mutationKey } = data;
|
||||
|
||||
// If env is not development check for the mutation key.
|
||||
if (env !== "development") {
|
||||
// If mutation key was not provided.
|
||||
if (!mutationKey) {
|
||||
console.info("CRONJOB: REFUSED - no mutation key was provided.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// If provided mutation key is invalid.
|
||||
if (mutationKey !== envMutationKey) {
|
||||
console.info(
|
||||
"CRONJOB: REFUSED - mutation key provided was incorrect."
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const latestDailyStats = await getLatestDailyStat();
|
||||
|
||||
// If there is a daily stats documents.
|
||||
if (latestDailyStats !== null) {
|
||||
// Check if the latest document is for today.
|
||||
if (isDailyStatToday(String(latestDailyStats.createdAt))) {
|
||||
console.info("Cron job refused: latest document is current date.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const date = new Date().toISOString();
|
||||
|
||||
await prisma.dailyStats.create({ data: { createdAt: date } });
|
||||
// Create new daily stats document.
|
||||
const createdAtDate = new Date().toISOString();
|
||||
await prisma.dailyStats.create({ data: { createdAt: createdAtDate } });
|
||||
|
||||
// Get every daily stats documents.
|
||||
const allStats = await prisma.dailyStats.findMany({});
|
||||
|
||||
// Add all stats into one object.
|
||||
const calculatedStats = allStats.reduce(
|
||||
(acc, curr) => {
|
||||
const links = (acc.linksDeleted += curr.linksDeleted);
|
||||
@@ -153,12 +183,15 @@ export const resolvers = {
|
||||
}
|
||||
);
|
||||
|
||||
// Take the total stats document.
|
||||
const totalStats = await prisma.totalStats.findFirst({
|
||||
orderBy: {
|
||||
createdAt: "desc"
|
||||
}
|
||||
});
|
||||
|
||||
// Update the total stats document with the new total.
|
||||
console.info("CRONJOB: Creating new document.");
|
||||
return await prisma.totalStats.update({
|
||||
where: {
|
||||
createdAt: totalStats?.createdAt
|
||||
@@ -181,25 +214,37 @@ export const resolvers = {
|
||||
const { groupID, groupName, groupUsername, mutationKey } = data;
|
||||
const groupIDInt = BigInt(groupID);
|
||||
|
||||
// If env is not development check for the mutation key.
|
||||
if (env !== "development") {
|
||||
// If mutation key was not provided.
|
||||
if (!mutationKey) {
|
||||
console.info("ADD GROUP: REFUSED - no mutation key was provided.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// If provided mutation key is invalid.
|
||||
if (mutationKey !== envMutationKey) {
|
||||
console.info(
|
||||
"ADD GROUP: REFUSED - mutation key provided was incorrect."
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to find the group's document.
|
||||
const existingGroup = await prisma.groups.findUnique({
|
||||
where: { telegramID: groupIDInt }
|
||||
});
|
||||
|
||||
// If the document was found.
|
||||
if (existingGroup !== null) {
|
||||
// Check if the document details are incorrect.
|
||||
if (
|
||||
existingGroup.name !== groupName ||
|
||||
existingGroup.username !== groupUsername
|
||||
) {
|
||||
// Return the document after updating the details.
|
||||
console.info("ADD GROUP: Updated group document.");
|
||||
return await prisma.groups.update({
|
||||
where: {
|
||||
telegramID: existingGroup.telegramID
|
||||
@@ -208,9 +253,12 @@ export const resolvers = {
|
||||
});
|
||||
}
|
||||
|
||||
// Return document without making changed.
|
||||
return existingGroup;
|
||||
}
|
||||
|
||||
// Return document after creating one for the group.
|
||||
console.info("ADD GROUP: Created new group document.");
|
||||
return await prisma.groups.create({
|
||||
data: {
|
||||
telegramID: groupIDInt,
|
||||
@@ -225,16 +273,27 @@ export const resolvers = {
|
||||
) => {
|
||||
const { groupID, linksDeleted, mutationKey } = data;
|
||||
|
||||
// If env is not development check for the mutation key.
|
||||
if (env !== "development") {
|
||||
// If mutation key was not provided.
|
||||
if (!mutationKey) {
|
||||
console.info(
|
||||
"INCREMENT GROUP: REFUSED - no mutation key was provided."
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
// If provided mutation key is invalid.
|
||||
if (mutationKey !== envMutationKey) {
|
||||
console.info(
|
||||
"INCREMENT GROUP: REFUSED - mutation key provided was incorrect."
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Return updated group document after incrementing it.
|
||||
console.info("INCREMENT GROUP: Incremented group document.");
|
||||
return await prisma.groups.update({
|
||||
where: { telegramID: BigInt(groupID) },
|
||||
data: { linksDeleted: { increment: linksDeleted } }
|
||||
@@ -252,22 +311,33 @@ export const resolvers = {
|
||||
) => {
|
||||
const { link, command, trigger, mutationKey } = data;
|
||||
|
||||
// If env is not development check for the mutation key.
|
||||
if (env !== "development") {
|
||||
// If mutation key was not provided.
|
||||
if (!mutationKey) {
|
||||
console.info("INCREMENT: REFUSED - no mutation key was provided.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// If provided mutation key is invalid.
|
||||
if (mutationKey !== envMutationKey) {
|
||||
console.info(
|
||||
"INCREMENT: REFUSED - mutation key provided was incorrect."
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Get latest daily stats.
|
||||
let latestDailyStats = await getLatestDailyStat();
|
||||
|
||||
// If there is a daily stats documents.
|
||||
if (latestDailyStats !== null) {
|
||||
// Check if the latest document is for today.
|
||||
if (!isDailyStatToday(String(latestDailyStats.createdAt))) {
|
||||
// Create new daily stats document.
|
||||
console.info("INCREMENT: Created new document.");
|
||||
const date = new Date().toISOString();
|
||||
|
||||
await prisma.dailyStats
|
||||
.create({ data: { createdAt: date } })
|
||||
.then(async () => {
|
||||
@@ -279,6 +349,8 @@ export const resolvers = {
|
||||
});
|
||||
}
|
||||
|
||||
// Return latest daily stats after incrementing it.
|
||||
console.info("INCREMENT: Incremented information on today's document.");
|
||||
return await prisma.dailyStats.update({
|
||||
where: { createdAt: latestDailyStats.createdAt },
|
||||
data: {
|
||||
|
||||
Reference in New Issue
Block a user