18 lines
567 B
TypeScript
18 lines
567 B
TypeScript
import { ApolloContext } from '@seed/interfaces/context';
|
|
import RoomModel from './room.model';
|
|
import RoomResolver from './room.resolver';
|
|
|
|
export const roomsGetOneByAccountsIds = async (ids: string[], toCreate?: { ctx: ApolloContext }): Promise<RoomModel> => {
|
|
const model = new RoomModel();
|
|
|
|
try {
|
|
const roomData = await model.getOne({ r: { $all: ids } }, null);
|
|
|
|
return roomData;
|
|
} catch (error) {
|
|
if (!toCreate) throw error;
|
|
|
|
return await new RoomResolver().roomsCreateOne({ accountIds: ids }, toCreate.ctx);
|
|
}
|
|
};
|