first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const user = await prisma.user.upsert({
|
||||
where: { mobile: '09382507041' },
|
||||
create: {
|
||||
mobile: '09382507041',
|
||||
name: 'کاربر ویژه',
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
update: {
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
});
|
||||
|
||||
const campaign = await prisma.campaign.findUnique({
|
||||
where: { slug: 'default-campaign' },
|
||||
});
|
||||
|
||||
if (campaign) {
|
||||
await prisma.userCampaign.upsert({
|
||||
where: {
|
||||
userId_campaignId: {
|
||||
userId: user.id,
|
||||
campaignId: campaign.id,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
userId: user.id,
|
||||
campaignId: campaign.id,
|
||||
totalChances: 10,
|
||||
usedChances: 0,
|
||||
},
|
||||
update: {
|
||||
totalChances: { increment: 10 },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
console.log('SUCCESS: User 09382507041 is authorized and ready with 10 chances!');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user