40 lines
944 B
TypeScript
40 lines
944 B
TypeScript
import db from "../../db"
|
|
import { Gitlab } from "../../types/gitlab"
|
|
|
|
const getFullUserMap = async (fullPipelineList: Gitlab.PipelineDetail[][]) => {
|
|
const userList: Gitlab.User[] = []
|
|
fullPipelineList.forEach((fullPipeline) => {
|
|
fullPipeline.forEach((item) => {
|
|
if (item.user && !userList.find((v) => v.id === item.user?.id)) {
|
|
userList.push(item.user)
|
|
}
|
|
})
|
|
})
|
|
|
|
const dbUserInfo = await Promise.all(
|
|
userList
|
|
.filter((v) => v.id !== 0)
|
|
.map((user) =>
|
|
db.user.upsert({
|
|
user_id: user.id,
|
|
username: user.username,
|
|
name: user.name,
|
|
avatar_url: user.avatar_url,
|
|
web_url: user.web_url,
|
|
})
|
|
)
|
|
)
|
|
const userMap: Record<string, string> = {}
|
|
dbUserInfo.forEach((item) => {
|
|
if (!item) return
|
|
userMap[item.user_id] = item.id
|
|
})
|
|
return userMap
|
|
}
|
|
|
|
const manageUser = {
|
|
getFullUserMap,
|
|
}
|
|
|
|
export default manageUser
|