mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
create recipient and short uid
This commit is contained in:
@ -37,6 +37,7 @@
|
|||||||
"react-hook-form": "^7.41.5",
|
"react-hook-form": "^7.41.5",
|
||||||
"react-pdf": "^6.2.2",
|
"react-pdf": "^6.2.2",
|
||||||
"sass": "^1.57.1",
|
"sass": "^1.57.1",
|
||||||
|
"short-uuid": "^4.2.2",
|
||||||
"typescript": "4.8.4"
|
"typescript": "4.8.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
47
apps/web/pages/api/recipients/index.ts
Normal file
47
apps/web/pages/api/recipients/index.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import {
|
||||||
|
defaultHandler,
|
||||||
|
defaultResponder,
|
||||||
|
getUserFromToken,
|
||||||
|
} from "@documenso/lib/server";
|
||||||
|
import prisma from "@documenso/prisma";
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import short from "short-uuid";
|
||||||
|
import { Document as PrismaDocument } from "@prisma/client";
|
||||||
|
|
||||||
|
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
const user = await getUserFromToken(req, res);
|
||||||
|
const { id: documentId } = req.query;
|
||||||
|
const body = req.body;
|
||||||
|
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
|
if (!documentId) {
|
||||||
|
res.status(400).send("Missing parameter documentId.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const document: PrismaDocument = await prisma.document.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: +documentId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// todo encapsulate entity ownerships
|
||||||
|
if (document.userId !== user.id) {
|
||||||
|
return res.status(401).send("User does not have access to this document.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await prisma.recipient.create({
|
||||||
|
data: {
|
||||||
|
documentId: +documentId,
|
||||||
|
email: body.email,
|
||||||
|
token: short.generate(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(201).end();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defaultHandler({
|
||||||
|
POST: Promise.resolve({ default: defaultResponder(postHandler) }),
|
||||||
|
});
|
||||||
33
package-lock.json
generated
33
package-lock.json
generated
@ -70,6 +70,7 @@
|
|||||||
"react-hook-form": "^7.41.5",
|
"react-hook-form": "^7.41.5",
|
||||||
"react-pdf": "^6.2.2",
|
"react-pdf": "^6.2.2",
|
||||||
"sass": "^1.57.1",
|
"sass": "^1.57.1",
|
||||||
|
"short-uuid": "^4.2.2",
|
||||||
"typescript": "4.8.4"
|
"typescript": "4.8.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -1219,6 +1220,11 @@
|
|||||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/any-base": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/any-base/-/any-base-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-uMgjozySS8adZZYePpaWs8cxB9/kdzmpX6SgJZ+wbz1K5eYk5QMYDVJaZKhxyIHUdnnJkfR7SVgStgH7LkGUyg=="
|
||||||
|
},
|
||||||
"node_modules/anymatch": {
|
"node_modules/anymatch": {
|
||||||
"version": "3.1.3",
|
"version": "3.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
||||||
@ -7470,6 +7476,18 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/short-uuid": {
|
||||||
|
"version": "4.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/short-uuid/-/short-uuid-4.2.2.tgz",
|
||||||
|
"integrity": "sha512-IE7hDSGV2U/VZoCsjctKX6l5t5ak2jE0+aeGJi3KtvjIUNuZVmHVYUjNBhmo369FIWGDtaieRaO8A83Lvwfpqw==",
|
||||||
|
"dependencies": {
|
||||||
|
"any-base": "^1.1.0",
|
||||||
|
"uuid": "^8.3.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/side-channel": {
|
"node_modules/side-channel": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
||||||
@ -8465,6 +8483,7 @@
|
|||||||
"react-hook-form": "^7.41.5",
|
"react-hook-form": "^7.41.5",
|
||||||
"react-pdf": "^6.2.2",
|
"react-pdf": "^6.2.2",
|
||||||
"sass": "^1.57.1",
|
"sass": "^1.57.1",
|
||||||
|
"short-uuid": "*",
|
||||||
"tailwindcss": "^3.2.4",
|
"tailwindcss": "^3.2.4",
|
||||||
"typescript": "4.8.4"
|
"typescript": "4.8.4"
|
||||||
},
|
},
|
||||||
@ -9266,6 +9285,11 @@
|
|||||||
"color-convert": "^2.0.1"
|
"color-convert": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"any-base": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/any-base/-/any-base-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-uMgjozySS8adZZYePpaWs8cxB9/kdzmpX6SgJZ+wbz1K5eYk5QMYDVJaZKhxyIHUdnnJkfR7SVgStgH7LkGUyg=="
|
||||||
|
},
|
||||||
"anymatch": {
|
"anymatch": {
|
||||||
"version": "3.1.3",
|
"version": "3.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
||||||
@ -13537,6 +13561,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
||||||
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="
|
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="
|
||||||
},
|
},
|
||||||
|
"short-uuid": {
|
||||||
|
"version": "4.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/short-uuid/-/short-uuid-4.2.2.tgz",
|
||||||
|
"integrity": "sha512-IE7hDSGV2U/VZoCsjctKX6l5t5ak2jE0+aeGJi3KtvjIUNuZVmHVYUjNBhmo369FIWGDtaieRaO8A83Lvwfpqw==",
|
||||||
|
"requires": {
|
||||||
|
"any-base": "^1.1.0",
|
||||||
|
"uuid": "^8.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"side-channel": {
|
"side-channel": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
||||||
|
|||||||
Reference in New Issue
Block a user