Skip to content

Commit

Permalink
style: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanHjelsethStorstad committed Jan 21, 2025
1 parent 2f813fe commit f6fdcfc
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/actions/licenses/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use server'
import { Licenses } from "@/services/licenses"
import { Action } from "../Action"
import { Action } from '@/actions/Action'
import { Licenses } from '@/services/licenses'

export const createLicenseAction = Action(Licenses.create)
export const createLicenseAction = Action(Licenses.create)
6 changes: 3 additions & 3 deletions src/actions/licenses/destroy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use server'
import { Licenses } from "@/services/licenses"
import { ActionNoData } from "../Action"
import { ActionNoData } from '@/actions/Action'
import { Licenses } from '@/services/licenses'

export const destroyLicenseAction = ActionNoData(Licenses.destroy)
export const destroyLicenseAction = ActionNoData(Licenses.destroy)
6 changes: 3 additions & 3 deletions src/actions/licenses/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server'

import { Licenses } from "@/services/licenses"
import { Action } from "@/actions/Action"
import { Licenses } from '@/services/licenses'
import { Action } from '@/actions/Action'

export const updateLicenseAction = Action(Licenses.update)
export const updateLicenseAction = Action(Licenses.update)
44 changes: 22 additions & 22 deletions src/app/admin/licenses/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import styles from './page.module.scss'
import { unwrapActionReturn } from '@/app/redirectToErrorPage'
import { readLicensesAction } from '@/actions/licenses/read'
import Link from 'next/link'
import { SettingsHeaderItemPopUp } from '@/app/_components/HeaderItems/HeaderItemPopUp'
import Form from '@/app/_components/Form/Form'
import { destroyLicenseAction } from '@/actions/licenses/destroy'
import { createLicenseAction } from '@/actions/licenses/create'
import TextInput from '@/UI/TextInput'
import { updateLicenseAction } from '@/actions/licenses/update'
import Link from 'next/link'

export default async function Licenses() {
const licenses = unwrapActionReturn(await readLicensesAction.bind(null, {})())
Expand Down Expand Up @@ -36,37 +36,37 @@ export default async function Licenses() {
</Link>
</td>
<td>
<SettingsHeaderItemPopUp PopUpKey={`LicenseSettings ${license.id}`}>
<Form
action={updateLicenseAction.bind(null, { id: license.id })}
title='Endre lisens'
submitText='Endre'
>
<TextInput name='name' label='Navn' defaultValue={license.name} />
<TextInput name='link' label='Link' defaultValue={license.link} />
</Form>
<SettingsHeaderItemPopUp PopUpKey={`LicenseSettings ${license.id}`}>
<Form
action={updateLicenseAction.bind(null, { id: license.id })}
title="Endre lisens"
submitText="Endre"
>
<TextInput name="name" label="Navn" defaultValue={license.name} />
<TextInput name="link" label="Link" defaultValue={license.link} />
</Form>

<Form
action={destroyLicenseAction.bind(null, { id: license.id })}
submitText="Slett"
submitColor="red"
refreshOnSuccess
/>
</SettingsHeaderItemPopUp>
<Form
action={destroyLicenseAction.bind(null, { id: license.id })}
submitText="Slett"
submitColor="red"
refreshOnSuccess
/>
</SettingsHeaderItemPopUp>
</td>
</tr>
))}
</tbody>
</table>

<Form
action={createLicenseAction.bind(null, {})}
title='Lag ny lisens'
submitText='Lag'
title="Lag ny lisens"
submitText="Lag"
refreshOnSuccess
>
<TextInput name='name' label='Navn' />
<TextInput name='link' label='Link' />
<TextInput name="name" label="Navn" />
<TextInput name="link" label="Link" />
</Form>
</div>
)
Expand Down
12 changes: 5 additions & 7 deletions src/services/licenses/create.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'server-only'
import { ServiceMethodHandler } from "@/services/ServiceMethodHandler"
import { createLicenseValidation } from './validation'
import { ServiceMethodHandler } from '@/services/ServiceMethodHandler'

export const create = ServiceMethodHandler({
withData: true,
validation: createLicenseValidation,
handler: async (prisma, _, data) => {
return await prisma.license.create({
data,
})
},
})
handler: async (prisma, _, data) => await prisma.license.create({
data,
}),
})
22 changes: 11 additions & 11 deletions src/services/licenses/destroy.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import 'server-only'
import { ServiceMethodHandler } from '../ServiceMethodHandler'
import { ServerError } from '../error'
import { ServiceMethodHandler } from '@/services/ServiceMethodHandler'
import { ServerError } from '@/services/error'

export const destroy = ServiceMethodHandler({
withData: false,
handler: async (prisma, params: { id: number }) => {
const { name: licenseName } = await prisma.license.findUniqueOrThrow({
where: { id: params.id },
const { name: licenseName } = await prisma.license.findUniqueOrThrow({
where: { id: params.id },
select: { name: true }
})

const imagesOfLicense = await prisma.image.findMany({
where: {
licenseName: licenseName
},
take: 1
const imagesOfLicense = await prisma.image.findMany({
where: {
licenseName
},
take: 1
})
if (imagesOfLicense.length > 0) {
throw new ServerError(
'UNPERMITTED CASCADE',
'UNPERMITTED CASCADE',
'Lisensen har bilder tilknyttet - slett bildene først eller endre lisensen på bildene'
)
}

await prisma.license.delete({ where: { id: params.id } })
}
})
})
2 changes: 1 addition & 1 deletion src/services/licenses/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'server-only'
import { destroy } from './destroy'
import { readAll } from './read'
import { ServiceMethod } from '@/services/ServiceMethod'
import { CreateLicenseAuther, DestroyLicenseAuther, UpdateLicenseAuther } from './Authers'
import { create } from './create'
import { update } from './update'
import { ServiceMethod } from '@/services/ServiceMethod'

export const Licenses = {
readAll: ServiceMethod({
Expand Down
4 changes: 2 additions & 2 deletions src/services/licenses/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'server-only'
import { updateLicenseValidation } from './validation'
import { ServiceMethodHandler } from '../ServiceMethodHandler'
import { ServiceMethodHandler } from '@/services/ServiceMethodHandler'

export const update = ServiceMethodHandler({
withData: true,
Expand All @@ -13,4 +13,4 @@ export const update = ServiceMethodHandler({
data
})
}
})
})
2 changes: 1 addition & 1 deletion src/services/licenses/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const baseLicenseValidation = new ValidationBase({
)
}
})

export const createLicenseValidation = baseLicenseValidation.createValidation({
keys: ['name', 'link'],
transformer: data => data
Expand Down

0 comments on commit f6fdcfc

Please sign in to comment.