diff --git a/desci-server/src/controllers/auth/index.ts b/desci-server/src/controllers/auth/index.ts index 49f777d5d..91d4ed082 100755 --- a/desci-server/src/controllers/auth/index.ts +++ b/desci-server/src/controllers/auth/index.ts @@ -1,6 +1,5 @@ export * from './login.js'; export * from './logout.js'; -export * from './register.js'; export * from './profile.js'; export * from './orcid.js'; export * from './magic.js'; diff --git a/desci-server/src/controllers/auth/orcid.ts b/desci-server/src/controllers/auth/orcid.ts index 9fc8e8944..03d7d9f2c 100755 --- a/desci-server/src/controllers/auth/orcid.ts +++ b/desci-server/src/controllers/auth/orcid.ts @@ -36,7 +36,7 @@ export const validateOrcid = async (req: Request, res: Response) => { res.send({ data, ok: true }); } catch (err) { logger.error({ err, fn: 'validateOrcid', req }); - res.status(400).send({ ok: false, err }); + res.status(400).send({ ok: false, msg: 'Validation failed' }); } }; @@ -144,7 +144,7 @@ const processOrcidConnect = async (req: Request, res: Response, closing: boolean return; } catch (err) { logger.error({ fn: 'processOrcidConnect', err }, 'error processing orcid connect'); - res.status(400).send({ err }); + res.status(400).send('Orcid connect failed'); } }; @@ -203,6 +203,6 @@ const processOrcidAuth = async (req: Request, res: Response, closing: boolean) = return; } catch (err) { logger.error({ fn: 'processOrcidAuth', err }, 'error processing orcid auth'); - res.status(400).send({ err }); + res.status(500).send({ msg: 'processing ORCID auth failed' }); } }; diff --git a/desci-server/src/controllers/auth/register.ts b/desci-server/src/controllers/auth/register.ts deleted file mode 100755 index 84900f77c..000000000 --- a/desci-server/src/controllers/auth/register.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Request, Response, NextFunction } from 'express'; - -import { prisma } from '../../client.js'; - -export const register = async (req: Request, res: Response, next: NextFunction) => { - const { email, tokendId } = req.body; - - if (!email) { - res.status(400).send({ ok: false }); - return; - } - - const user = await prisma.user.upsert({ - where: { - email, - }, - update: {}, - create: { - email, - isPatron: false, - isWarden: false, - isKeeper: false, - }, - }); - - res.send(user); - - // const userRepository = getRepository(User); - // try { - // const user = await userRepository.findOne({ where: { email } }); - - // if (user) { - // const customError = new CustomError(400, 'General', 'User already exists', [ - // `Email '${user.email}' already exists`, - // ]); - // return next(customError); - // } - - // try { - // const newUser = new User(); - // newUser.email = email; - - // await userRepository.save(newUser); - - // res.customSuccess(200, 'User successfully created.'); - // } catch (err) { - // const customError = new CustomError(400, 'Raw', `User '${email}' can't be created`, null, err); - // return next(customError); - // } - // } catch (err) { - // const customError = new CustomError(400, 'Raw', 'Error', null, err); - // return next(customError); - // } -}; diff --git a/desci-server/src/routes/v1/auth.ts b/desci-server/src/routes/v1/auth.ts index 5d2f7ad35..f7a107fe0 100755 --- a/desci-server/src/routes/v1/auth.ts +++ b/desci-server/src/routes/v1/auth.ts @@ -3,7 +3,6 @@ import { Router } from 'express'; import { login, logout, - register, profile, orcidAuth, orcidAuthClose, @@ -28,7 +27,6 @@ router.post('/login/did', asyncHandler(walletLogin)); router.get('/login/did/:walletAddress', asyncHandler(walletNonce)); router.delete('/logout', logout); router.get('/profile', [ensureUser], profile); -router.post('/register', register); router.get('/orcid/auth', orcidAuth); router.get('/orcid/auth/close', orcidAuthClose); router.get('/orcid/connect', orcidConnect); diff --git a/desci-server/src/services/Attestation.ts b/desci-server/src/services/Attestation.ts index b80a38817..5e5301768 100644 --- a/desci-server/src/services/Attestation.ts +++ b/desci-server/src/services/Attestation.ts @@ -126,6 +126,7 @@ export class AttestationService { } async create(data: Prisma.AttestationUncheckedCreateInput) { + logger.trace({ data }, 'AttestationService#create'); const community = await communityService.findCommunityById(data.communityId); if (!community) throw new CommunityNotFoundError(); @@ -133,7 +134,19 @@ export class AttestationService { const existing = await prisma.attestation.findFirst({ where: { name: data.name, communityId: data.communityId } }); if (existing) throw new DuplicateDataError(); - const attestation = await prisma.attestation.create({ data: { communityId: community.id, ...data } }); + const attestation = await prisma.attestation.create({ + data: { + name: data.name, + description: data.description, + image_url: data.image_url, + verified_image_url: data.verified_image_url, + protected: data.protected, + canMintDoi: data.canMintDoi, + canUpdateOrcid: data.canUpdateOrcid, + communityId: community.id, + templateId: data.templateId, + }, + }); await this.#publishVersion({ name: attestation.name, @@ -181,12 +194,22 @@ export class AttestationService { canUpdateOrcid: data.canUpdateOrcid, }, }); - await this.#publishVersion({ + const attestationVersion = await this.#publishVersion({ name: data.name as string, description: data.description, image_url: data.image_url, attestationId: attestation.id, }); + + const communityEntryAttestation = await prisma.communityEntryAttestation.findFirst({ + where: { attestationId: attestation.id }, + }); + if (communityEntryAttestation) { + await prisma.communityEntryAttestation.update({ + where: { id: communityEntryAttestation.id }, + data: { attestationVersionId: attestationVersion.id }, + }); + } const updated = await this.findAttestationById(attestation.id); return updated; }