MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / run

Function run

packages/maintenance/src/import-users.ts:55–107  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53};
54
55async function run() {
56 if (process.argv.length < 4) {
57 throw 'missing params, try: npm run script:import-user -- "accountId" "/full/path/file.csv"';
58 }
59 const accountId = process.argv[2];
60 const file = fs.readFileSync(process.argv[3]);
61
62 const { data } = Papa.parse(file.toString(), {
63 header: true,
64 skipEmptyLines: true,
65 });
66 const users = data as Users[];
67
68 const toUpsert: Prisma.usersCreateInput[] = users.map((user) => {
69 return {
70 account: { connect: { id: accountId } },
71 anonymousAlias: generateRandomWordSlug(),
72 ...(shouldCreateAuth(user.status) && {
73 auth: {
74 connectOrCreate: {
75 create: {
76 email: user.email,
77 password: v4(),
78 salt: v4(),
79 accountId,
80 },
81 where: { email: user.email },
82 },
83 },
84 }),
85 displayName: user.displayname || user.username,
86 externalUserId: user.userid,
87 role: mapRole(user.status),
88 isAdmin: isAdmin(user.status),
89 isBot: isBot(user.status),
90 };
91 });
92
93 await Promise.all(
94 toUpsert.map((data) =>
95 prisma.users.upsert({
96 create: data,
97 update: data,
98 where: {
99 externalUserId_accountsId: {
100 accountsId: accountId,
101 externalUserId: data.externalUserId!,
102 },
103 },
104 })
105 )
106 );
107}
108
109run().catch(console.error);

Callers 1

import-users.tsFile · 0.70

Calls 6

generateRandomWordSlugFunction · 0.90
shouldCreateAuthFunction · 0.85
mapRoleFunction · 0.85
isAdminFunction · 0.85
mapMethod · 0.80
isBotFunction · 0.70

Tested by

no test coverage detected