stacker.news/worker/repin.js

39 lines
809 B
JavaScript
Raw Permalink Normal View History

2023-11-21 23:32:22 +00:00
export async function repin ({ name, models }) {
// get the id
const id = name.slice('repin-'.length)
if (id.length === 0 || isNaN(id)) {
console.log('repin id not found in', name)
return
}
2022-01-17 17:41:17 +00:00
2023-11-21 23:32:22 +00:00
// get the latest item with this id
const pinId = Number(id)
const current = await models.item.findFirst(
{
where: {
pinId
},
orderBy: {
createdAt: 'desc'
2022-01-17 17:41:17 +00:00
}
}
2023-11-21 23:32:22 +00:00
)
2022-01-17 17:41:17 +00:00
2023-11-21 23:32:22 +00:00
if (!current) {
console.log('could not find existing item for pin', name)
return
2022-01-17 17:41:17 +00:00
}
2023-11-21 23:32:22 +00:00
// create a new item with matching 1) title, text, and url and 2) setting pinId
await models.item.create({
data: {
title: current.title,
text: current.text,
url: current.url,
userId: current.userId,
subName: current.subName,
pinId
}
})
2022-01-17 17:41:17 +00:00
}