Skip to content

Commit

Permalink
async-labs#173 upgraded some packages
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Jun 7, 2022
1 parent 57f0c5e commit 3c2cec3
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 155 deletions.
9 changes: 5 additions & 4 deletions saas/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
"helmet": "4.1.0-rc.2",
"highlight.js": "^10.5.0",
"lodash": "^4.17.20",
"marked": "^1.2.7",
"mongoose": "^5.10.15",
"marked": "^4.0.16",
"mongoose": "^6.3.5",
"node-fetch": "^2.6.1",
"passport": "^0.4.1",
"passport-google-oauth": "^2.0.0",
"passwordless": "^1.1.3",
"passwordless-tokenstore": "^0.0.10",
"socket.io": "^4.2.0",
"stripe": "^8.129.0",
"typescript": "^4.1.3",
"typescript": "^4.7.3",
"winston": "^3.3.3"
},
"devDependencies": {
Expand All @@ -53,6 +53,7 @@
"@types/express-session": "^1.15.8",
"@types/jest": "^22.2.3",
"@types/lodash": "^4.14.108",
"@types/marked": "^4.0.3",
"@types/mongoose": "^5.5.43",
"@types/node": "^12.12.2",
"@types/node-fetch": "^1.6.9",
Expand All @@ -67,6 +68,6 @@
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1"
"ts-node": "^10.8.1"
}
}
10 changes: 6 additions & 4 deletions saas/api/server/models/Discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { generateRandomSlug } from '../utils/slugify';
import Team, { TeamDocument } from './Team';
import Post from './Post';

mongoose.set('useFindAndModify', false);

const mongoSchema = new mongoose.Schema({
createdUserId: {
type: String,
Expand Down Expand Up @@ -138,7 +136,9 @@ class DiscussionClass extends mongoose.Model {
throw new Error('Bad data');
}

const discussion = await this.findById(id).select('teamId createdUserId').setOptions({ lean: true });
const discussion = await this.findById(id)
.select('teamId createdUserId')
.setOptions({ lean: true });

const team = await this.checkPermissionAndGetTeam({
userId,
Expand Down Expand Up @@ -184,7 +184,9 @@ class DiscussionClass extends mongoose.Model {
throw new Error('Bad data');
}

const team = await Team.findById(teamId).select('memberIds teamLeaderId').setOptions({ lean: true });
const team = await Team.findById(teamId)
.select('memberIds teamLeaderId')
.setOptions({ lean: true });

if (!team || team.memberIds.indexOf(userId) === -1) {
throw new Error('Team not found');
Expand Down
2 changes: 0 additions & 2 deletions saas/api/server/models/Invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import getEmailTemplate from './EmailTemplate';
import Team from './Team';
import User, { UserDocument } from './User';

mongoose.set('useFindAndModify', false);

const mongoSchema = new mongoose.Schema({
teamId: {
type: String,
Expand Down
16 changes: 10 additions & 6 deletions saas/api/server/models/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import * as mongoose from 'mongoose';

import * as he from 'he';
import * as hljs from 'highlight.js';
import * as marked from 'marked';
import { marked } from 'marked';

import Discussion from './Discussion';
import Team from './Team';

mongoose.set('useFindAndModify', false);

const mongoSchema = new mongoose.Schema({
createdUserId: {
type: String,
Expand Down Expand Up @@ -156,7 +154,9 @@ class PostClass extends mongoose.Model {
throw new Error('Bad data');
}

const post = await this.findById(id).select('createdUserId discussionId').setOptions({ lean: true });
const post = await this.findById(id)
.select('createdUserId discussionId')
.setOptions({ lean: true });

await this.checkPermissionAndGetTeamAndDiscussion({
userId,
Expand All @@ -180,7 +180,9 @@ class PostClass extends mongoose.Model {
throw new Error('Bad data');
}

const post = await this.findById(id).select('createdUserId discussionId content').setOptions({ lean: true });
const post = await this.findById(id)
.select('createdUserId discussionId content')
.setOptions({ lean: true });

await this.checkPermissionAndGetTeamAndDiscussion({
userId,
Expand Down Expand Up @@ -216,7 +218,9 @@ class PostClass extends mongoose.Model {
throw new Error('Permission denied');
}

const team = await Team.findById(discussion.teamId).select('memberIds slug').setOptions({ lean: true });
const team = await Team.findById(discussion.teamId)
.select('memberIds slug')
.setOptions({ lean: true });

if (!team || team.memberIds.indexOf(userId) === -1) {
throw new Error('Team not found');
Expand Down
3 changes: 0 additions & 3 deletions saas/api/server/models/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { cancelSubscription } from '../stripe';
import { generateRandomSlug } from '../utils/slugify';
import User from './User';

mongoose.set('useFindAndModify', false);

const mongoSchema = new mongoose.Schema({
name: {
type: String,
Expand Down Expand Up @@ -203,7 +201,6 @@ class TeamClass extends mongoose.Model {
throw new Error('Permission denied');
}

// @ts-expect-error probably problem with @types/mongoose, works with $set but not $pull
await this.findByIdAndUpdate(teamId, { $pull: { memberIds: userId } });
}

Expand Down
2 changes: 0 additions & 2 deletions saas/api/server/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import Team, { TeamDocument } from './Team';

import { getListOfInvoices } from '../stripe';

mongoose.set('useFindAndModify', false);

const mongoSchema = new mongoose.Schema({
slug: {
type: String,
Expand Down
2 changes: 1 addition & 1 deletion saas/api/server/passwordless-token-mongostore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ MongoStore.prototype.storeOrUpdateByEmail = async function addEmail(email: strin
return obj.uid;
}

const uid = mongoose.Types.ObjectId().toHexString();
const uid = new mongoose.Types.ObjectId().toHexString();
await PasswordlessToken.updateOne({ uid }, { email }, { upsert: true });

return uid;
Expand Down
22 changes: 14 additions & 8 deletions saas/api/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ require('dotenv').config();
const dev = process.env.NODE_ENV !== 'production';
const port = process.env.PORT || 8000;

const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
};

mongoose.connect(dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL, options);
mongoose.connect(dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL);

// check connection
(async () => {
try {
await mongoose.connect(dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL);
logger.info('connected to db');

// async tasks, for ex, inserting email templates to db
// logger.info('finished async tasks');
} catch (err) {
console.log('error: ' + err);
}
})();

const server = express();

Expand Down
Loading

0 comments on commit 3c2cec3

Please sign in to comment.