api entities
This commit is contained in:
@ -2,14 +2,13 @@ import { MongoClient, Db } from 'mongodb';
|
||||
|
||||
class Mongo {
|
||||
private client: MongoClient;
|
||||
private dbName: string;
|
||||
|
||||
constructor(uri: string) {
|
||||
this.client = new MongoClient(uri);
|
||||
}
|
||||
|
||||
getDb(): Db {
|
||||
return this.client.db(this.dbName);
|
||||
getDb(dbName: string): Db {
|
||||
return this.client.db(dbName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,28 @@
|
||||
import { CreateUserBody, User, UserInfo } from '@core';
|
||||
import { User } from '../../entities/user';
|
||||
import { Services } from '../express/server';
|
||||
|
||||
export function Create(
|
||||
services: Services,
|
||||
): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
|
||||
): (tracker: string, user: User) => Promise<User> {
|
||||
const { db } = services;
|
||||
const coll = db.collection('users');
|
||||
const coll = db.collection<User>('users');
|
||||
const readUser = Read(services);
|
||||
|
||||
return async (tracker, user) => {
|
||||
await coll.insertOne(user);
|
||||
return {
|
||||
name: 'test',
|
||||
};
|
||||
return readUser(tracker, user.uuid);
|
||||
};
|
||||
}
|
||||
|
||||
export function Read(
|
||||
services: Services,
|
||||
): (tracker: string, uuid: string) => Promise<User> {
|
||||
const { db } = services;
|
||||
const coll = db.collection<User>('users');
|
||||
|
||||
return async (tracker, uuid) => {
|
||||
const user = await coll.findOne({ uuid });
|
||||
|
||||
return new User(user || { name: 'not found' });
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user