Skip to content

Commit

Permalink
Merge pull request #718 from desci-labs/develop
Browse files Browse the repository at this point in the history
Fixes to main
  • Loading branch information
kadamidev authored Dec 16, 2024
2 parents 6923bfa + 5c46fbc commit f3b0811
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 62 deletions.
1 change: 0 additions & 1 deletion desci-server/src/controllers/auth/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
6 changes: 3 additions & 3 deletions desci-server/src/controllers/auth/orcid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}
};

Expand Down Expand Up @@ -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');
}
};

Expand Down Expand Up @@ -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' });
}
};
54 changes: 0 additions & 54 deletions desci-server/src/controllers/auth/register.ts

This file was deleted.

2 changes: 0 additions & 2 deletions desci-server/src/routes/v1/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Router } from 'express';
import {
login,
logout,
register,
profile,
orcidAuth,
orcidAuthClose,
Expand All @@ -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);
Expand Down
27 changes: 25 additions & 2 deletions desci-server/src/services/Attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,27 @@ 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();

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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f3b0811

Please sign in to comment.