Skip to content

Commit

Permalink
change weekly.ts and fix many bugs (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
L0510410 authored Aug 11, 2022
1 parent 85a924e commit 3452ad4
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 270 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Use Node.js ${{matrix.node-version}}
uses: actions/setup-node@v1
with:
node-version: "14.x"
node-version: "16.x"

- name: get yarn cache path
id: yarn-cache-dir-path
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EESAST 后端 API

### 环境

- node 14 / npm
- node 16 / npm
- yarn
- TypeScript
- MongoDB
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"morgan": "1.10.0",
"multer": "1.4.4",
"node-cron": "3.0.1",
"node-fetch": "3.2.10",
"node-fetch": "2.6.2",
"nodemailer": "6.7.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ db.once("open", () => {
});

export const client = new GraphQLClient(
`${process.env.HASURA_URL}/v1/graphql`,
`${process.env.HASURA_GRAPHQL_ENDPOINT}/v1/graphql`,
{
headers: {
"Content-Type": "application/json",
Expand Down
11 changes: 2 additions & 9 deletions src/routes/emails.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import express from "express";
import { GraphQLClient, gql } from "graphql-request";
import { gql } from "graphql-request";
import { sendEmail } from "../helpers/email";
import { newMentorApplicationTemplate } from "../helpers/htmlTemplates";
import hasura from "../middlewares/hasura";
import { client } from "..";

const router = express.Router();

router.post("/events", hasura, async (req, res) => {
const client = new GraphQLClient(`${process.env.HASURA_URL}/v1/graphql`, {
headers: {
"Content-Type": "application/json",
"x-hasura-admin-secret": process.env.HASURA_GRAPHQL_ADMIN_SECRET!,
},
});

const data = req.body?.event?.data?.new;
const table = req.body?.table?.name;
const op = req.body?.event?.op;
Expand Down Expand Up @@ -84,7 +78,6 @@ router.post("/events", hasura, async (req, res) => {
}

return res.status(200).end();
break;
} catch (e) {
console.error(e);
res.status(500).end();
Expand Down
64 changes: 22 additions & 42 deletions src/routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
} from "../helpers/htmlTemplates";
import authenticate, { JwtPayload } from "../middlewares/authenticate";
import { validateEmail, validatePassword } from "../helpers/validate";
import fetch from "node-fetch";
import hasura from "../middlewares/hasura";
import type { MongoError } from "mongodb";
import { gql } from "graphql-request";
import { client } from "..";

const router = express.Router();

Expand Down Expand Up @@ -305,25 +306,16 @@ router.post("/verify", async (req, res) => {
return res.status(200).end();
}
} else if (type === "regular") {
await fetch(`${process.env.API_URL}/v1/graphql`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-hasura-admin-secret": process.env.HASURA_GRAPHQL_ADMIN_SECRET!,
},
body: JSON.stringify({
query: `
mutation InsertUser($_id: String!) {
insert_user_one(object: {_id: $_id}) {
_id
}
await client.request(
gql`
mutation InsertUser($_id: String!) {
insert_user_one(object: {_id: $_id}) {
_id
}
`,
variables: {
_id: user._id,
},
}),
});
}
`,
{ _id: user._id }
);

user.update({ emailVerified: true }, null, (err) => {
if (err) {
Expand Down Expand Up @@ -447,30 +439,18 @@ router.post("/actions/user_by_role", hasura, async (req, res) => {

try {
const users = await User.find({ role });

const response = await fetch(`${process.env.API_URL}/v1/graphql`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-hasura-admin-secret": process.env.HASURA_GRAPHQL_ADMIN_SECRET!,
},
body: JSON.stringify({
query: `
query GetUsersByIds($ids: [String!]) {
user(where: {_id: {_in: $ids}}) {
_id
name
department
}
const usersByRole = await client.request(
gql`
query GetUsersByIds($ids: [String!]) {
user(where: {_id: {_in: $ids}}) {
_id
name
department
}
`,
variables: {
ids: users.map((u) => u._id),
},
}),
});

const usersByRole: any = await response.json();
}
`,
{ ids: users.map((u) => u._id) }
)

if (usersByRole?.data?.user) {
return res.status(200).json(usersByRole?.data?.user);
Expand Down
Loading

0 comments on commit 3452ad4

Please sign in to comment.