Skip to content

Commit 7210153

Browse files
authored
Merge branch 'main' into 1177-return-200-on-reject
2 parents 629309a + 00c11bd commit 7210153

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/db/file/repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const createRepo = async (repo: Repo): Promise<Repo> => {
9797
if (err) {
9898
reject(err);
9999
} else {
100-
resolve(doc ? toClass(doc, Repo.prototype) : null);
100+
resolve(toClass(doc, Repo.prototype));
101101
}
102102
});
103103
});

src/db/helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export const toClass = function (obj: any, proto: any) {
2-
obj = JSON.parse(JSON.stringify(obj));
3-
obj.__proto__ = proto;
4-
return obj;
1+
export const toClass = function <T, U>(obj: T, proto: U): U {
2+
const out = JSON.parse(JSON.stringify(obj));
3+
out.__proto__ = proto;
4+
return out as U;
55
};
66

77
export const trimTrailingDotGit = (str: string): string => {

src/db/mongo/repo.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ const collectionName = 'repos';
77

88
export const getRepos = async (query: any = {}): Promise<Repo[]> => {
99
const collection = await connect(collectionName);
10-
const docs = collection.find(query).toArray();
10+
const docs = await collection.find(query).toArray();
1111
return _.chain(docs)
1212
.map((x) => toClass(x, Repo.prototype))
1313
.value();
1414
};
1515

1616
export const getRepo = async (name: string): Promise<Repo | null> => {
17-
name = name.toLowerCase();
1817
const collection = await connect(collectionName);
19-
const doc = collection.findOne({ name: { $eq: name } });
18+
const doc = await collection.findOne({ name: { $eq: name.toLowerCase() } });
2019
return doc ? toClass(doc, Repo.prototype) : null;
2120
};
2221

2322
export const getRepoByUrl = async (repoUrl: string): Promise<Repo | null> => {
2423
const collection = await connect(collectionName);
25-
const doc = collection.findOne({ name: { $eq: repoUrl.toLowerCase() } });
24+
const doc = await collection.findOne({ url: { $eq: repoUrl } });
2625
return doc ? toClass(doc, Repo.prototype) : null;
2726
};
2827

2928
export const getRepoById = async (_id: string): Promise<Repo | null> => {
3029
const collection = await connect(collectionName);
31-
const doc = collection.findOne({ _id: new ObjectId(_id) });
30+
const doc = await collection.findOne({ _id: new ObjectId(_id) });
3231
return doc ? toClass(doc, Repo.prototype) : null;
3332
};
3433

src/db/mongo/users.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ const collectionName = 'users';
77

88
export const findUser = async function (username: string): Promise<User | null> {
99
const collection = await connect(collectionName);
10-
const doc = collection.findOne({ username: { $eq: username.toLowerCase() } });
10+
const doc = await collection.findOne({ username: { $eq: username.toLowerCase() } });
1111
return doc ? toClass(doc, User.prototype) : null;
1212
};
1313

1414
export const findUserByEmail = async function (email: string): Promise<User | null> {
1515
const collection = await connect(collectionName);
16-
const doc = collection.findOne({ email: { $eq: email.toLowerCase() } });
16+
const doc = await collection.findOne({ email: { $eq: email.toLowerCase() } });
1717
return doc ? toClass(doc, User.prototype) : null;
1818
};
1919

2020
export const findUserByOIDC = async function (oidcId: string): Promise<User | null> {
2121
const collection = await connect(collectionName);
22-
const doc = collection.findOne({ oidcId: { $eq: oidcId } });
22+
const doc = await collection.findOne({ oidcId: { $eq: oidcId } });
2323
return doc ? toClass(doc, User.prototype) : null;
2424
};
2525

@@ -32,7 +32,7 @@ export const getUsers = async function (query: any = {}): Promise<User[]> {
3232
}
3333
console.log(`Getting users for query = ${JSON.stringify(query)}`);
3434
const collection = await connect(collectionName);
35-
const docs = collection.find(query).project({ password: 0 }).toArray();
35+
const docs = await collection.find(query).project({ password: 0 }).toArray();
3636
return _.chain(docs)
3737
.map((x) => toClass(x, User.prototype))
3838
.value();

0 commit comments

Comments
 (0)