fix magnet creation
This commit is contained in:
parent
1f4d4938c9
commit
553de595d2
@ -39,8 +39,8 @@ export default async function indexRoutes(fastify: FastifyInstance): Promise<voi
|
||||
createdAt: 'desc'
|
||||
}
|
||||
})
|
||||
logger.debug('vods as follows')
|
||||
logger.debug(vods)
|
||||
logger.trace('vods as follows')
|
||||
logger.trace(vods)
|
||||
|
||||
const vtubers = await prisma.vtuber.findMany({
|
||||
take: 3,
|
||||
|
@ -127,144 +127,7 @@ export default async function streamsRoutes(
|
||||
|
||||
});
|
||||
|
||||
fastify.get('/picks', async function (request: FastifyRequest, reply: FastifyReply) {
|
||||
|
||||
const targetUser = await getTargetUser(request, reply)
|
||||
|
||||
const waifuChoicePoolSize = targetUser.waifuChoicePoolSize
|
||||
const picks = await prisma.pick.findMany({
|
||||
where: {
|
||||
userId: targetUser.id
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: waifuChoicePoolSize,
|
||||
include: {
|
||||
waifu: true
|
||||
}
|
||||
})
|
||||
reply.send({ data: picks })
|
||||
|
||||
})
|
||||
|
||||
fastify.post('/picks', async function (request: FastifyRequest, reply: FastifyReply) {
|
||||
const targetUser = await getTargetUser(request, reply)
|
||||
|
||||
const userId = targetUser.id
|
||||
const { waifuId } = request.body as { waifuId: number }
|
||||
logger.debug(`userId=${userId}, waifuId=${waifuId}`)
|
||||
|
||||
if (!userId) {
|
||||
return reply.code(400).send({ error: 'Missing userId' })
|
||||
}
|
||||
if (!waifuId) {
|
||||
return reply.code(400).send({ error: 'Mising waifuId' })
|
||||
}
|
||||
|
||||
const picks = await prisma.pick.create({
|
||||
data: {
|
||||
userId,
|
||||
waifuId
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
include: {
|
||||
twitchToken: true
|
||||
}
|
||||
},
|
||||
waifu: true,
|
||||
}
|
||||
})
|
||||
|
||||
logger.debug("~~~~~~ adding graphileWorker job")
|
||||
await fastify.graphileWorker.addJob('consolidate_twitch_channel_rewards', { userId })
|
||||
|
||||
|
||||
reply.send({ id: picks.id })
|
||||
})
|
||||
|
||||
fastify.delete('/picks', async function (request: FastifyRequest, reply: FastifyReply) {
|
||||
const userId = request.session.get('user_id')
|
||||
const { pickId } = request.body as { pickId: number }
|
||||
logger.debug(`userId=${userId}, pickId=${pickId}`)
|
||||
|
||||
if (!userId || !pickId) {
|
||||
return reply.code(400).send({ error: 'Missing userId or pickId' })
|
||||
}
|
||||
|
||||
await prisma.pick.delete({
|
||||
where: {
|
||||
id: pickId
|
||||
}
|
||||
})
|
||||
|
||||
reply.send(pickId)
|
||||
})
|
||||
|
||||
fastify.get('/redeems', async function (request, reply) {
|
||||
const userId = request.session.get('user_id')
|
||||
const user = await prisma.user.findFirstOrThrow({
|
||||
where: {
|
||||
id: userId
|
||||
}
|
||||
})
|
||||
const redeems = await prisma.redeem.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
createdAt: {
|
||||
gt: new Date(user.clearRedeemsCursor)
|
||||
}
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: user.maxOnScreenWaifus,
|
||||
include: {
|
||||
waifu: true
|
||||
}
|
||||
})
|
||||
reply.send({ data: redeems })
|
||||
})
|
||||
|
||||
fastify.post('/redeems', async function (request, reply) {
|
||||
const targetUser = await getTargetUser(request, reply);
|
||||
logger.debug(`we are creating a redeem and the targetuser is id=${targetUser.id}`)
|
||||
|
||||
const { pickId } = request.body as { pickId: number };
|
||||
|
||||
if (!pickId) throw new Error('pickId was missing');
|
||||
|
||||
const pick = await prisma.pick.findFirstOrThrow({
|
||||
where: { id: pickId }
|
||||
});
|
||||
|
||||
const redeem = await prisma.redeem.create({
|
||||
data: {
|
||||
user: { connect: { id: targetUser.id } },
|
||||
waifu: { connect: { id: pick.waifuId } },
|
||||
viewerTwitchId: targetUser.twitchId
|
||||
},
|
||||
include: {
|
||||
waifu: true
|
||||
}
|
||||
});
|
||||
|
||||
reply.send({ data: redeem });
|
||||
});
|
||||
|
||||
fastify.delete('/redeems', async function (request, reply) {
|
||||
const targetUser = await getTargetUser(request, reply);
|
||||
logger.debug(`we are deleting redeems and the targetuser is id=${targetUser.id}`)
|
||||
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: targetUser.id
|
||||
},
|
||||
data: {
|
||||
clearRedeemsCursor: new Date().toISOString()
|
||||
}
|
||||
});
|
||||
|
||||
reply.send({ data: [] });
|
||||
})
|
||||
|
||||
fastify.get('/streams', function (request, reply) {
|
||||
reply.send('This feature is coming soon.')
|
||||
@ -333,52 +196,7 @@ export default async function streamsRoutes(
|
||||
// reply.send(redeem)
|
||||
// })
|
||||
|
||||
fastify.get('/obs/:obsToken', async function (
|
||||
request: FastifyRequest<{ Params: { obsToken: string } }>,
|
||||
reply: FastifyReply
|
||||
) {
|
||||
const { obsToken } = request.params
|
||||
const { cdnOrigin } = constants
|
||||
await prisma.user.findFirstOrThrow({
|
||||
where: {
|
||||
obsToken
|
||||
}
|
||||
});
|
||||
|
||||
return reply.view("obs.ejs", { obsToken, cdnOrigin }, { layout: 'layouts/main.hbs' });
|
||||
});
|
||||
|
||||
|
||||
|
||||
fastify.get('/obs/:obsToken/redeems', async function (
|
||||
request: FastifyRequest<{ Params: { obsToken: string } }>,
|
||||
reply: FastifyReply
|
||||
) {
|
||||
|
||||
const user = await prisma.user.findFirstOrThrow({
|
||||
where: {
|
||||
obsToken: request.params.obsToken
|
||||
}
|
||||
})
|
||||
|
||||
const redeems = await prisma.redeem.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
createdAt: {
|
||||
gt: new Date(user.clearRedeemsCursor)
|
||||
}
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: user.maxOnScreenWaifus,
|
||||
include: {
|
||||
waifu: true
|
||||
}
|
||||
})
|
||||
|
||||
reply.send({ data: redeems })
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
@ -33,58 +33,6 @@ export default async function usersRoutes(
|
||||
reply.send(user)
|
||||
})
|
||||
|
||||
fastify.put('/settings', async function (request, reply) {
|
||||
const { onBehalfOf } = request.query as OnBehalfQuery;
|
||||
const userId = request.session.get('user_id');
|
||||
|
||||
// Get the authenticated user
|
||||
const user = await prisma.user.findFirstOrThrow({
|
||||
where: { id: userId }
|
||||
});
|
||||
|
||||
logger.debug('onbehalfof=' + onBehalfOf)
|
||||
|
||||
// Determine which user is being updated
|
||||
const targetUser = onBehalfOf
|
||||
? await prisma.user.findFirstOrThrow({ where: { twitchName: onBehalfOf } })
|
||||
: user;
|
||||
|
||||
const raw = request.body as Record<string, any>;
|
||||
|
||||
const waifuChoicePoolSize = raw.waifuChoicePoolSize ? Number(raw.waifuChoicePoolSize) : undefined;
|
||||
const maxOnScreenWaifus = raw.maxOnScreenWaifus ? Number(raw.maxOnScreenWaifus) : undefined;
|
||||
const redeemCost = raw.redeemCost ? Number(raw.redeemCost) : undefined;
|
||||
|
||||
const data: Record<string, any> = {
|
||||
waifuChoicePoolSize,
|
||||
maxOnScreenWaifus,
|
||||
twitchName: targetUser.twitchName,
|
||||
redeemCost,
|
||||
};
|
||||
|
||||
// Only the actual user can modify editor-related fields
|
||||
if (!onBehalfOf) {
|
||||
data.editorTwitchNames = Array.isArray(raw.editorTwitchNames)
|
||||
? raw.editorTwitchNames
|
||||
: [raw.editorTwitchNames].filter(Boolean);
|
||||
|
||||
data.modsAreEditors = Boolean(raw.modsAreEditors);
|
||||
}
|
||||
|
||||
logger.debug('>>> data s follows')
|
||||
logger.debug(data)
|
||||
logger.debug('target user is as follows')
|
||||
logger.debug(targetUser)
|
||||
|
||||
await prisma.user.update({
|
||||
where: { id: targetUser.id },
|
||||
data
|
||||
});
|
||||
await fastify.graphileWorker.addJob('consolidate_twitch_channel_rewards', { userId })
|
||||
|
||||
reply.send(data);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -157,7 +157,7 @@ export default async function main(payload: any, helpers: Helpers) {
|
||||
}
|
||||
})
|
||||
|
||||
const spawn = await getNanoSpawn();
|
||||
// const spawn = await getNanoSpawn();
|
||||
|
||||
// * [x] load vod
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user