Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
fix #16 全てのテーブルにcreatedAtとupdatedAtを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
yogarasu committed Aug 21, 2022
1 parent 7561a51 commit a8b5dee
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
13 changes: 9 additions & 4 deletions libs/category2.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class CategoryClient {
discordClient: DiscordClient,
categoryNames: string[]
) {
// Create discord category
const discordCategories: DiscordCategory[] = await Promise.all(
// Create many discord category
const discordCategories = await Promise.all(
categoryNames.map(async (categoryName) => {
const newCategory = await retry(
async () =>
Expand All @@ -33,11 +33,13 @@ export class CategoryClient {
id: 0,
categoryId: newCategory.id,
name: newCategory.name,
}
createdAt: newCategory.createdAt,
updatedAt: newCategory.createdAt,
} as DiscordCategory
})
)

// Update discord category data
// Update many discord category data
await this.updateManyDiscordCategory(discordCategories)

return discordCategories
Expand Down Expand Up @@ -82,10 +84,13 @@ export class CategoryClient {
update: {
categoryId: category.categoryId,
name: category.name,
updatedAt: category.updatedAt,
},
create: {
categoryId: category.categoryId,
name: category.name,
createdAt: category.createdAt,
updatedAt: category.updatedAt,
},
})
)
Expand Down
16 changes: 12 additions & 4 deletions libs/channel2.mts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ChannelClient {
const slackChannels = await this.getSlackChannelFile(channelFilePath)

// Convert slack channel data
const newSlackChannels: SlackChannel[] = slackChannels.map((channel) => {
const newSlackChannels = slackChannels.map((channel) => {
if (
channel.id === undefined ||
channel.name === undefined ||
Expand All @@ -51,7 +51,9 @@ export class ChannelClient {
topic: channel.topic.value,
isArchived: channel.is_archived,
pins: channel.pins?.map((pin) => pin.id).join(",") || null,
}
createdAt: new Date(),
updatedAt: new Date(),
} as SlackChannel
})

// Update slack channel data
Expand Down Expand Up @@ -99,7 +101,9 @@ export class ChannelClient {
slackChannelId: channel.channelId,
topic: result.topic,
isArchived: channel.isArchived,
}
createdAt: result.createdAt,
updatedAt: result.createdAt,
} as DiscordChannel
})
)

Expand Down Expand Up @@ -173,14 +177,16 @@ export class ChannelClient {
topic: channel.topic,
isArchived: channel.isArchived,
pins: channel.pins,
createdAt: channel.createdAt,
updatedAt: channel.updatedAt,
},
})
)
await this.client.$transaction([...query])
}

/**
* Update many discord channel
* Update many discord channel data
* @param channels
*/
async updateManyDiscordChannel(channels: DiscordChannel[]) {
Expand All @@ -204,6 +210,8 @@ export class ChannelClient {
slackChannelId: channel.slackChannelId,
topic: channel.topic,
isArchived: channel.isArchived,
createdAt: channel.createdAt,
updatedAt: channel.updatedAt,
},
})
)
Expand Down
10 changes: 7 additions & 3 deletions libs/user2.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class UserClient {
const slackUsers = await this.getSlackUserFile(userFilePath)

// Convert slack user data
const newSlackUsers: SlackUser[] = slackUsers.map((user) => {
const newSlackUsers = slackUsers.map((user) => {
if (
user.id === undefined ||
user.is_bot === undefined ||
Expand All @@ -51,7 +51,9 @@ export class UserClient {
imageUrl: user.profile.image_512,
isBot: user.is_bot,
isDeleted: user.deleted,
}
createdAt: new Date(),
updatedAt: new Date(),
} as SlackUser
})

// Update slack user data
Expand All @@ -70,7 +72,7 @@ export class UserClient {
}

/**
* Update many slack user
* Update many slack user data
* @param users
*/
async updateManySlackUser(users: SlackUser[]) {
Expand All @@ -94,6 +96,8 @@ export class UserClient {
imageUrl: user.imageUrl,
isBot: user.isBot,
isDeleted: user.isDeleted,
createdAt: user.createdAt,
updatedAt: user.updatedAt,
},
})
)
Expand Down
14 changes: 11 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ model SlackChannel {
isArchived Boolean
pins String?
discordChannels DiscordChannel[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}

model DiscordChannel {
Expand All @@ -28,21 +30,27 @@ model DiscordChannel {
isArchived Boolean
slackChannel SlackChannel @relation(fields: [slackChannelId], references: [channelId])
discordCategory DiscordCategory @relation(fields: [categoryId], references: [categoryId])
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}

model DiscordCategory {
id Int @id @default(autoincrement())
name String
categoryId String @unique
discordChannels DiscordChannel[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}

model SlackUser {
id Int @id @default(autoincrement())
userId String @unique
id Int @id @default(autoincrement())
userId String @unique
name String
email String? @unique
email String? @unique
imageUrl String
isBot Boolean
isDeleted Boolean
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}

0 comments on commit a8b5dee

Please sign in to comment.