Skip to content

Commit

Permalink
fix: fix AWS lambda db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonadams committed Sep 8, 2020
1 parent d8604d9 commit 3a1c896
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 40 deletions.
16 changes: 6 additions & 10 deletions apps/server/lambda/src/server/db-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ import {
*
* @param connection mongoose connection
*/
export async function initDbSchemasModels(conn: Connection) {
await Promise.all([
createUserModel(conn),
createRefreshTokenModel(conn),
createVerificationTokenModel(conn),
createTodoModel(conn),
createTodoNoteModel(conn),
]);

return conn;
export function initDbSchemasModels(conn: Connection) {
createUserModel(conn);
createRefreshTokenModel(conn);
createVerificationTokenModel(conn);
createTodoModel(conn);
createTodoNoteModel(conn);
}
8 changes: 2 additions & 6 deletions libs/server/core-data/src/lib/auth/refresh-token.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ export class RefreshTokenClass extends Model {

refreshTokenSchema.loadClass(RefreshTokenClass);

export async function createRefreshTokenModel(
con: Connection
): Promise<IRefreshTokenModel> {
const m = con.model<IRefreshTokenDocument, IRefreshTokenModel>(
export function createRefreshTokenModel(con: Connection) {
con.model<IRefreshTokenDocument, IRefreshTokenModel>(
refreshTokenDbKey,
refreshTokenSchema
);
await m.createCollection();
return m;
}

export function getRefreshTokenModel(con: Connection): IRefreshTokenModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ export class VerificationTokenClass extends Model {

verificationTokenSchema.loadClass(VerificationTokenClass);

export async function createVerificationTokenModel(
con: Connection
): Promise<IVerificationTokenModel> {
const m = con.model<IVerificationTokenDocument, IVerificationTokenModel>(
export function createVerificationTokenModel(con: Connection) {
con.model<IVerificationTokenDocument, IVerificationTokenModel>(
verificationTokenDbKey,
verificationTokenSchema
);
await m.createCollection();
return m;
}

export function getVerificationTokenModel(
Expand Down
13 changes: 3 additions & 10 deletions libs/server/core-data/src/lib/todos/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,16 @@ export const todoSchemaDefinition: TSchemaDefinition<ITodoNote> = {
body: String,
createdOn: {
type: Date,
default: new Date(),
default: Date.now(),
},
};

export const todoNoteSchema = new Schema<ITodoNote>(todoSchemaDefinition, {
...defaultSchemaOptions,
});

export async function createTodoNoteModel(
con: Connection
): Promise<ITodoNoteModel> {
const m = con.model<ITodoNoteDocument, ITodoNoteModel>(
todoNoteDbKey,
todoNoteSchema
);
m.createCollection();
return m;
export function createTodoNoteModel(con: Connection) {
con.model<ITodoNoteDocument, ITodoNoteModel>(todoNoteDbKey, todoNoteSchema);
}

export function getTodoNoteModel(con: Connection): ITodoNoteModel {
Expand Down
6 changes: 2 additions & 4 deletions libs/server/core-data/src/lib/todos/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ todoSchema.post('findOneAndRemove', async (doc: ITodoDocument) => {
);
});

export async function createTodoModel(con: Connection): Promise<ITodoModel> {
const m = con.model<ITodoDocument, ITodoModel>(todoDbKey, todoSchema);
await m.createCollection();
return m;
export function createTodoModel(con: Connection) {
con.model<ITodoDocument, ITodoModel>(todoDbKey, todoSchema);
}

export function getTodoModel(con: Connection): ITodoModel {
Expand Down
6 changes: 2 additions & 4 deletions libs/server/core-data/src/lib/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ export class UserClass extends Model {

userSchema.loadClass(UserClass);

export async function createUserModel(con: Connection): Promise<IUserModel> {
const m = con.model<IUserDocument, IUserModel>(userDbKey, userSchema);
await m.createCollection();
return m;
export function createUserModel(con: Connection) {
con.model<IUserDocument, IUserModel>(userDbKey, userSchema);
}

export function getUserModel(con: Connection): IUserModel {
Expand Down

0 comments on commit 3a1c896

Please sign in to comment.