add ntfy
This commit is contained in:
parent
bad6ab1acc
commit
e0ef03a944
|
@ -0,0 +1,8 @@
|
|||
import fetch from "node-fetch";
|
||||
|
||||
export async function ntfy(message: string) {
|
||||
fetch("https://ntfy.sh/uhrv932r4e5w6zmi4-ld", {
|
||||
method: "POST",
|
||||
body: message,
|
||||
}).catch(console.error);
|
||||
}
|
|
@ -15,6 +15,7 @@ import { outsideProviders } from "../middleware/setup-passport";
|
|||
import * as T from "../../../website/src/types/account-types";
|
||||
import env from "../lib/env-vars";
|
||||
import Stripe from "stripe";
|
||||
import { ntfy } from "./ntfy";
|
||||
|
||||
const stripe = new Stripe(env.stripeSecretKey, {
|
||||
apiVersion: "2022-08-01",
|
||||
|
@ -163,6 +164,7 @@ export async function createNewUser(
|
|||
email: input.email || "",
|
||||
token: email.token,
|
||||
});
|
||||
ntfy(`new LingDocs user ${input.name} - ${input.email}`);
|
||||
const user = await insertLingdocsUser(newUser);
|
||||
return user;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import express, { Response } from "express";
|
||||
import * as T from "../../../website/src/types/account-types";
|
||||
import { addFeedback } from "../lib/couch-db";
|
||||
import { ntfy } from "../lib/ntfy";
|
||||
// import env from "../lib/env-vars";
|
||||
|
||||
// TODO: ADD PROPER ERROR HANDLING THAT WILL RETURN JSON ALWAYS
|
||||
|
||||
function sendResponse(res: Response, payload: T.APIResponse) {
|
||||
return res.send(payload);
|
||||
return res.send(payload);
|
||||
}
|
||||
|
||||
const feedbackRouter = express.Router();
|
||||
|
@ -15,22 +16,25 @@ const feedbackRouter = express.Router();
|
|||
* receives a piece of feedback
|
||||
*/
|
||||
feedbackRouter.put("/", (req, res, next) => {
|
||||
const { anonymous, ...feedback } = req.body;
|
||||
const user = anonymous
|
||||
? "anonymous"
|
||||
: req.user
|
||||
? req.user.name
|
||||
: "not logged in";
|
||||
addFeedback({
|
||||
user,
|
||||
feedback,
|
||||
}).then(() => {
|
||||
res.send({ ok: true, message: "feedback received" });
|
||||
}).catch((e) => {
|
||||
console.error("error receiving feedback");
|
||||
console.error("feedback missed", feedback);
|
||||
console.error(e);
|
||||
next("error receiving feedback");
|
||||
const { anonymous, ...feedback } = req.body;
|
||||
const user = anonymous
|
||||
? "anonymous"
|
||||
: req.user
|
||||
? req.user.name
|
||||
: "not logged in";
|
||||
addFeedback({
|
||||
user,
|
||||
feedback,
|
||||
})
|
||||
.then(() => {
|
||||
ntfy(JSON.stringify(feedback));
|
||||
res.send({ ok: true, message: "feedback received" });
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("error receiving feedback");
|
||||
console.error("feedback missed", feedback);
|
||||
console.error(e);
|
||||
next("error receiving feedback");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue