Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: save point change history #45

Merged
merged 2 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/point-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ const pointSystem = async (msg, client, prisma) => {
author_id: msg.author.id,
},
});
await prisma.point_history.create({
data: {
point_id: points.id,
change: `+${pointValue}`,
author_id: msg.author.id
}
});
const embed = new MessageEmbed()
.setTitle('WPU for Moderator')
.setThumbnail(msg.guild.iconURL({ dynamic: true }))
Expand Down Expand Up @@ -173,6 +180,13 @@ const pointSystem = async (msg, client, prisma) => {
author_id: msg.author.id,
},
});
await prisma.point_history.create({
data: {
point_id: points.id,
change: `-${pointValue}`,
author_id: msg.author.id
}
});
const embed = new MessageEmbed()
.setTitle('WPU for Moderator')
.setThumbnail(msg.guild.iconURL({ dynamic: true }))
Expand Down
15 changes: 15 additions & 0 deletions prisma/migrations/20220122095845_add_point_history/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- CreateTable
CREATE TABLE `point_history` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`point_id` BIGINT NOT NULL,
`change` VARCHAR(191) NOT NULL,
`reason` TEXT NULL,
`author_id` VARCHAR(255) NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `point_history` ADD CONSTRAINT `point_history_point_id_fkey` FOREIGN KEY (`point_id`) REFERENCES `point`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
12 changes: 12 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ model point {
author_id String? @db.VarChar(255)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
point_log point_history[]
}

model point_history {
id BigInt @id @default(autoincrement())
point_id BigInt
change String
reason String? @db.Text
author_id String @db.VarChar(255)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
point point @relation(fields: [point_id], references: [id], onDelete: Cascade)
}