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