Skip to content

Commit

Permalink
fix: Mandatory pages are created for first user
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat Saxena committed Sep 30, 2022
1 parent c039fb0 commit aebab33
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/web/graphql/users/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ export async function createUser({
newUser.lead = lead;
const user = await UserModel.create(newUser);

await initMandatoryPages(domain, user);
if (!notTheFirstUserOfDomain) {
await initMandatoryPages(domain, user);
}

return user;
}
5 changes: 5 additions & 0 deletions apps/web/pages/api/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import { setLoginSession } from "../../../lib/auth";
import { responses } from "../../../config/strings";
import connectDb from "../../../middlewares/connect-db";
import User from "../../../models/User";
import { error } from "../../../services/logger";

passport.use(magicLinkStrategy);

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
error(err.message, {
fileName: `/api/auth/login.ts`,
stack: err.stack,
});
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
8 changes: 8 additions & 0 deletions apps/web/pages/api/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ import jwtStrategy from "../../lib/jwt";
import ApiRequest from "../../models/ApiRequest";
import connectDb from "../../middlewares/connect-db";
import constants from "../../config/constants";
import { error } from "../../services/logger";
import { responses } from "../../config/strings";

passport.use(jwtStrategy);

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
if (err.message.indexOf(responses.domain_doesnt_exist) === -1) {
error(err.message, {
fileName: `/api/graph.ts`,
stack: err.stack,
});
}
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
5 changes: 5 additions & 0 deletions apps/web/pages/api/media/[mediaId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import connectDb from "../../../middlewares/connect-db";
import verifyDomain from "../../../middlewares/verify-domain";
import verifyJwt from "../../../middlewares/verify-jwt";
import ApiRequest from "../../../models/ApiRequest";
import { error } from "../../../services/logger";
import * as medialitService from "../../../services/medialit";

passport.use(jwtStrategy);

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
error(err.message, {
fileName: `/api/media/[mediaId].ts`,
stack: err.stack,
});
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
5 changes: 5 additions & 0 deletions apps/web/pages/api/media/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import connectDb from "../../../middlewares/connect-db";
import verifyDomain from "../../../middlewares/verify-domain";
import verifyJwt from "../../../middlewares/verify-jwt";
import ApiRequest from "../../../models/ApiRequest";
import { error } from "../../../services/logger";
import * as medialitService from "../../../services/medialit";

passport.use(jwtStrategy);

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
error(err.message, {
fileName: `/api/media/index.ts`,
stack: err.stack,
});
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
5 changes: 5 additions & 0 deletions apps/web/pages/api/media/presigned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import connectDb from "../../../middlewares/connect-db";
import verifyDomain from "../../../middlewares/verify-domain";
import verifyJwt from "../../../middlewares/verify-jwt";
import ApiRequest from "../../../models/ApiRequest";
import { error } from "../../../services/logger";
import * as medialitService from "../../../services/medialit";

passport.use(jwtStrategy);

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
error(err.message, {
fileName: `/api/media/presigned.ts`,
stack: err.stack,
});
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
5 changes: 5 additions & 0 deletions apps/web/pages/api/payment/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CourseModel, { Course } from "../../../models/Course";
import { getPaymentMethod } from "../../../payments";
import PurchaseModel from "../../../models/Purchase";
import finalizePurchase from "../../../lib/finalize-purchase";
import { error } from "../../../services/logger";

const { transactionSuccess, transactionFailed, transactionInitiated } =
constants;
Expand All @@ -20,6 +21,10 @@ passport.use(jwtStrategy);

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
error(err.message, {
fileName: `/api/payment/initiate.ts`,
stack: err.stack,
});
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
5 changes: 5 additions & 0 deletions apps/web/pages/api/payment/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import verifyDomain from "../../../middlewares/verify-domain";
import verifyJwt from "../../../middlewares/verify-jwt";
import ApiRequest from "../../../models/ApiRequest";
import PurchaseModel, { Purchase } from "../../../models/Purchase";
import { error } from "../../../services/logger";

passport.use(jwtStrategy);

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
error(err.message, {
fileName: `/api/payment/verify.ts`,
stack: err.stack,
});
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
5 changes: 5 additions & 0 deletions apps/web/pages/api/payment/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import verifyDomain from "../../../middlewares/verify-domain";
import ApiRequest from "../../../models/ApiRequest";
import PurchaseModel, { Purchase } from "../../../models/Purchase";
import { getPaymentMethod } from "../../../payments";
import { error } from "../../../services/logger";
const { transactionSuccess } = constants;

export default nc<NextApiRequest, NextApiResponse>({
onError: (err, req, res, next) => {
error(err.message, {
fileName: `/api/payment/webhook.ts`,
stack: err.stack,
});
res.status(500).json({ error: err.message });
},
onNoMatch: (req, res) => {
Expand Down
5 changes: 4 additions & 1 deletion apps/web/services/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export const warn = async (

export const error = async (
message: string,
metadata?: Record<string, unknown>
metadata?: {
fileName?: string;
stack?: Record<string, unknown>;
}
) => {
await Log.create({
severity: severityError,
Expand Down

0 comments on commit aebab33

Please sign in to comment.