Skip to content

Commit

Permalink
chore: fix type errors in prisma package
Browse files Browse the repository at this point in the history
  • Loading branch information
sjschlapbach committed May 30, 2024
1 parent 1c2bc14 commit f041a56
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 34 deletions.
4 changes: 4 additions & 0 deletions packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"@types/bcryptjs": "^2.4.2",
"@types/node": "^18.17.4",
"@types/ramda": "^0.29.3",
"@types/turndown": "^5.0.4",
"@types/uuid": "^9.0.8",
"@types/xml-js": "^1.0.0",
"@types/xml2js": "^0.4.14",
"bcryptjs": "2.4.3",
"cross-env": "7.0.3",
"dotenv": "16.0.3",
Expand All @@ -40,6 +43,7 @@
"tsup": "7.2.0",
"turndown": "7.1.2",
"typescript": "5.1.6",
"uuid": "^9.0.1",
"uuidv4": "6.2.13",
"xml2js": "0.6.2"
},
Expand Down
8 changes: 7 additions & 1 deletion packages/prisma/src/data/data/TEST.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Prisma from '../../../dist'
import { AchievementType } from '../../client'
const { ElementType, SessionStatus, OrderType } = Prisma
const { ElementType, SessionStatus } = Prisma

export const QUESTIONS = [
{
Expand Down Expand Up @@ -183,9 +183,11 @@ export const SESSIONS = [
blocks: [
{
questions: [2, 4],
timeLimit: undefined,
},
{
questions: [4, 2],
timeLimit: undefined,
},
],
},
Expand All @@ -201,9 +203,11 @@ export const SESSIONS = [
blocks: [
{
questions: [0, 1, 2, 3, 4],
timeLimit: undefined,
},
{
questions: [0, 1, 2, 3, 4],
timeLimit: undefined,
},
],
},
Expand All @@ -219,9 +223,11 @@ export const SESSIONS = [
blocks: [
{
questions: [0, 1, 2, 3, 4],
timeLimit: undefined,
},
{
questions: [0, 1, 2, 3, 4],
timeLimit: 30,
},
],
},
Expand Down
17 changes: 10 additions & 7 deletions packages/prisma/src/data/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,13 +921,13 @@ export function prepareGroupActivityClues({
]
}

export function extractQuizInfo(doc: typeof xmlDoc, formulaTagId?: number) {
const turndown = Turndown()
export function extractQuizInfo(doc: any, formulaTagId?: number) {
const turndown = new Turndown()

return {
title: doc.box.title[0],
description: doc.box.description[0],
elements: doc.box.cards[0].card.map((card) => {
elements: doc.box.cards[0].card.map((card: any) => {
const hasFormula =
card.question[0].text[0].includes('\\(') ||
card.answer[0].text[0].includes('\\(')
Expand Down Expand Up @@ -990,6 +990,7 @@ export function extractQuizInfo(doc: typeof xmlDoc, formulaTagId?: number) {
}

export async function processQuizInfo(fileName: string, formulaTagId?: number) {
// @ts-ignore
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

Expand All @@ -1011,7 +1012,7 @@ export async function prepareFlashcardsFromFile(
const quizInfo = await processQuizInfo(fileName, formulaTagId)

const elementsFC = await Promise.allSettled(
quizInfo.elements.map(async (data) => {
quizInfo.elements.map(async (data: any) => {
const flashcard = await prismaClient.element.upsert({
where: {
originalId: data.originalId,
Expand All @@ -1037,11 +1038,13 @@ export async function prepareFlashcardsFromFile(
})
)

if (elementsFC.some((el) => el.status === 'rejected')) {
if (
elementsFC.some((el: PromiseSettledResult<any>) => el.status === 'rejected')
) {
throw new Error('Failed to seed some flashcard elements')
}

const elements = elementsFC.map((el) => el.value)
const elements = elementsFC.map((el: any) => el.value)

return elements
}
Expand Down Expand Up @@ -1074,7 +1077,7 @@ export async function prepareContentElements(
throw new Error('Failed to seed some content elements')
}

const elements = elementsCE.map((el) => el.value)
const elements = elementsCE.map((el: any) => el.value)

return elements
}
14 changes: 7 additions & 7 deletions packages/prisma/src/data/seedBF2.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Prisma from '../../dist'
import { USER_ID_BF2 } from './constants'
// import { USER_ID_BF2 } from './constants'
// import * as R from 'ramda'
// import { prepareQuestionInstance } from './helpers.js'

async function seed(prisma: Prisma.PrismaClient) {
if (process.env.ENV !== 'development') process.exit(1)

const questions = await prisma.element.findMany({
orderBy: { id: 'desc' },
where: {
ownerId: USER_ID_BF2,
},
})
// const questions = await prisma.element.findMany({
// orderBy: { id: 'desc' },
// where: {
// ownerId: USER_ID_BF2,
// },
// })

// const GROUP_ACTIVITY_ID = 'b83657a5-4d19-449d-b378-208b7cb2e8e0'
// const groupActivity1BF2 = await prisma.groupActivity.upsert({
Expand Down
4 changes: 3 additions & 1 deletion packages/prisma/src/data/seedFlashcards.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { v4 as uuidv4 } from 'uuid'
import Prisma, {
ElementInstanceType,
ElementOrderType,
Expand Down Expand Up @@ -45,7 +46,7 @@ async function seedFlashcardSet(
createMany: {
data: [
{
migrationId: el.originalId,
migrationId: el.originalId ?? uuidv4(),
originalId: el.originalId,
order: ix,
type: ElementInstanceType.PRACTICE_QUIZ,
Expand Down Expand Up @@ -280,6 +281,7 @@ export async function seedFlashcards(prismaClient: Prisma.PrismaClient) {

// if main module, run this
const prismaClient = new Prisma.PrismaClient()
// @ts-ignore
await seedFlashcards(prismaClient)
.then((res) => {
console.log('res', res)
Expand Down
11 changes: 7 additions & 4 deletions packages/prisma/src/data/seedTEST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ async function seedTest(prisma: Prisma.PrismaClient) {
prisma.liveSession.upsert(
await prepareSession({
...data,
status: data.status ?? 'PREPARED',
blocks: data.blocks.map((block, ix) => ({
...block,
order: ix,
questions: questionsTest
.filter((q) => block.questions.includes(parseInt(q.originalId!)))
.map(async (q) => q),
expiresAt: undefined,
timeLimit: block.timeLimit,
questions: questionsTest.filter((q) =>
block.questions.includes(parseInt(q.originalId!))
),
})),
ownerId: USER_ID_TEST,
courseId: COURSE_ID_TEST,
Expand Down Expand Up @@ -1025,6 +1027,7 @@ Mehr bla bla...

const prismaClient = new Prisma.PrismaClient()

// @ts-ignore
await seedTest(prismaClient)
.catch((e) => {
console.error(e)
Expand Down
6 changes: 6 additions & 0 deletions packages/prisma/src/data/seedUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ async function seedUser(prisma: Prisma.PrismaClient) {
name: '',
displayName: '',
ownerId: user.id,
pinCode: 483726,
startDate: new Date(),
endDate: new Date(new Date().setFullYear(new Date().getFullYear() + 10)),
groupDeadlineDate: new Date(
new Date().setFullYear(new Date().getFullYear() + 5)
),
})
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/prisma/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"src/data/*": "esm",
"src/scripts/*": "esm"
}
}
},
"exclude": ["src/client", "src/scripts"]
}
48 changes: 35 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f041a56

Please sign in to comment.