Hi Peter \o/
My code is on a private repo, I can add you but we’ll have to process via MP
( and, it’s on bitbucket ).
Below you will find the scratching example of a .ts
that gets ignored on build ( sorry if your eyes bleed, as you may recall, I’m brand new to the js-gig
).
Also, I’ve had a look at your file ( which allows me to understand how I incorrectly summoned the currentUser
), and comparatively I’m not sure I’d understand what would be so messed up in the following example that would justify it not being included in the build.
I’ll build your project locally to have a look though 
import { context } from '@redwoodjs/api'
import { db } from 'src/lib/db'
import { InterfacePayload, Status } from 'src/lib/utils'
import { getDefaultCollection } from 'src/services/collections/collections.js'
type OwnershipProps = {
id: string
}
const ownership: (props: OwnershipProps) => Promise<object> = function ({
id,
}) {
return db.ownership.findOne({
where: { id },
include: {
book: {
select: {
title: true,
covers: true,
},
},
collection: {
select: {
id: true,
name: true,
},
},
},
})
}
const ownerships: () => Promise<object> = () =>
db.user
.findOne({
where: { id: context?.currentUser?.id },
include: {
ownerships: {
include: {
book: {
include: { authors: true },
},
collection: { select: { id: true, name: true } },
},
},
},
})
.then(
(result: object) => result?.ownerships,
(reason: string) => reason
)
type ClaimBookOwnershipProps = {
bookId: string
rate: number
}
async function claimBookOwnership({
bookId,
rate,
}: ClaimBookOwnershipProps): Promise<InterfacePayload> {
const defaultCollection = await getDefaultCollection({
id: context.currentUser.id,
})
return db.ownership
.upsert({
where: {
book_user: { bookId, collectionId: defaultCollection.id },
},
create: {
rate,
collection: {
connect: {
id_name: { id: defaultCollection.id, name: defaultCollection.name },
},
},
book: { connect: { id: bookId } },
User: { connect: { id: context?.currentUser?.id } },
},
update: {
rate,
},
select: {
book: {
select: { title: true },
},
},
})
.then(
({ book }) => {
const claimBookOwnershipSuccess = `'${book?.title}' successfully added`
return {
data: book,
message: claimBookOwnershipSuccess,
status: Status.success,
}
},
(reason) => {
const claimBookOwnershipFailure = `Book couldn't be added ( ${reason} ).`
return {
message: claimBookOwnershipFailure,
status: Status.failure,
}
}
)
}
type UpdateOwnershipProps = {
id: string
data: { rate: number; note: string }
}
async function updateOwnership({
id,
input,
}: UpdateOwnershipProps): Promise<InterfacePayload> {
return db.ownership
.update({
data: { ...input, updatedAt: new Date() },
where: { id },
include: {
book: {
select: {
title: true,
covers: true,
},
},
},
})
.then(
(ownership) => ({
status: Status.success,
message: `Book '${ownership.book.title}' successfully updated!`,
data: ownership,
}),
(reason) => ({ status: Status.failure, message: reason })
)
}
export { ownership, ownerships, claimBookOwnership, updateOwnership }