diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 7265822..1cf8020 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -19,12 +19,12 @@ model Minecraft {
valid Boolean @default(true)
slim Boolean @default(false)
- user User? @relation(fields: [userId], references: [id])
- userId Int? @unique
+ user User? @relation(fields: [userId], references: [id])
+ userId String? @unique
}
model User {
- id Int @id @default(autoincrement())
+ id String @id
username String @default("")
reserved_name String?
name String @default("")
@@ -44,7 +44,7 @@ model User {
model UserSettings {
id Int @id @default(autoincrement())
User User @relation(fields: [userId], references: [id])
- userId Int @unique
+ userId String @unique
banned Boolean @default(false)
profile_theme Int @default(0)
autoload Boolean @default(true)
@@ -63,7 +63,7 @@ model Sessions {
sessionId String @unique @default("")
User_Agent String @default("")
User User @relation(fields: [userId], references: [id])
- userId Int
+ userId String
}
model Bandage {
@@ -75,7 +75,7 @@ model Bandage {
base64_slim String @default("")
split_type Boolean @default(false)
User User? @relation("UserBandages", fields: [userId], references: [id])
- userId Int?
+ userId String?
creationDate DateTime @default(now())
stars User[] @relation("UserStars")
categories Category[] @relation("Categories")
diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts
index 767acaf..7efb058 100644
--- a/src/notifications/notifications.service.ts
+++ b/src/notifications/notifications.service.ts
@@ -28,7 +28,8 @@ export class NotificationService {
return { data: notifications, total_count: count };
}
- async createNotification(userId: number, notification: Notifications) {
+ async createNotification(userId: string | null, notification: Notifications) {
+ if (!userId) return;
const notification_db = await this.prisma.notifications.create({
data: {
users: { connect: { id: userId } },
diff --git a/src/oauth/oauth.service.ts b/src/oauth/oauth.service.ts
index 37b4919..7881654 100644
--- a/src/oauth/oauth.service.ts
+++ b/src/oauth/oauth.service.ts
@@ -8,6 +8,7 @@ import { UserService } from 'src/user/user.service';
const discord_url = "https://discord.com/api/v10";
const pwgood = "447699225078136832"; // pwgood server id
+const EPOCH = 1672531200000n;
interface DiscordResponse {
token_type: string,
@@ -78,6 +79,12 @@ export const hasAccess = (user: UserFull | undefined, level: number) => {
return user_roles.includes(level) || user_roles.includes(RolesEnum.SuperAdmin);
}
+const generateSnowflake = (increment = 0n) => {
+ const timestamp = BigInt(Date.now()) - EPOCH;
+ const snowflake = (timestamp << 22n) | increment;
+ return snowflake.toString();
+}
+
@Injectable()
export class OauthService {
@@ -159,9 +166,12 @@ export class OauthService {
return { message: "You are not on ppl", statusCode: 403 };
}
+ const users_count = await this.prisma.user.count();
+
const user_db = await this.prisma.user.upsert({
where: { discordId: ds_user.id },
create: {
+ id: generateSnowflake(BigInt(users_count)),
discordId: ds_user.id,
username: ds_user.username,
name: ds_user.global_name || ds_user.username,
diff --git a/src/workshop/bandage.service.ts b/src/workshop/bandage.service.ts
index 617a310..3390f00 100644
--- a/src/workshop/bandage.service.ts
+++ b/src/workshop/bandage.service.ts
@@ -377,14 +377,14 @@ export class BandageService {
const difference = bandage_categories.filter((element) => !validated_categories.includes(element));
const difference_after = validated_categories.filter((element) => !bandage_categories.includes(element));
if (difference_after.includes(moderation_id[1])) {
- this.notifications.createNotification(bandage.userId as number, {
+ this.notifications.createNotification(bandage.userId, {
content: `Повязка ${bandage.title} была отклонена. Пожалуйста, свяжитесь с администрацией для уточнения причин.`,
type: 2
});
}
else if (moderation_id.some(element => difference.includes(element))) {
- this.notifications.createNotification(bandage.userId as number, {
+ this.notifications.createNotification(bandage.userId, {
content: `Повязка ${bandage.title} успешно прошла проверку и теперь доступна остальным в мастерской!`,
type: 1
});