fix: cleanups for asset

This commit is contained in:
Wyatt Johnson
2018-07-11 16:35:20 -06:00
parent 35ba69c8ed
commit 871206740f
4 changed files with 31 additions and 11 deletions
@@ -1,15 +1,16 @@
import DataLoader from "dataloader";
import TenantContext from "talk-server/graph/tenant/context";
import {
Asset,
findOrCreateAsset,
FindOrCreateAssetInput,
retrieveManyAssets,
} from "talk-server/models/asset";
import { findOrCreate } from "talk-server/services/assets";
export default (ctx: TenantContext) => ({
findOrCreate: (input: FindOrCreateAssetInput) =>
findOrCreateAsset(ctx.db, ctx.tenant.id, input),
findOrCreate(ctx.db, ctx.tenant, input),
asset: new DataLoader<string, Asset | null>(ids =>
retrieveManyAssets(ctx.db, ctx.tenant.id, ids)
),
@@ -6,7 +6,7 @@ import { create } from "talk-server/services/comments";
export default (ctx: TenantContext) => ({
create: (input: GQLCreateCommentInput): Promise<Comment> => {
// FIXME: remove tenant + user !
return create(ctx.db, ctx.tenant.id, {
return create(ctx.db, ctx.tenant, {
author_id: ctx.user!.id,
asset_id: input.assetID,
body: input.body,
+21
View File
@@ -0,0 +1,21 @@
import { Db } from "mongodb";
import {
findOrCreateAsset,
FindOrCreateAssetInput,
} from "talk-server/models/asset";
import { Tenant } from "talk-server/models/tenant";
export type FindOrCreateAsset = FindOrCreateAssetInput;
export async function findOrCreate(
db: Db,
tenant: Tenant,
input: FindOrCreateAsset
) {
// TODO: check to see if the tenant has enabled lazy asset creation.
const asset = await findOrCreateAsset(db, tenant.id, input);
return asset;
}
+6 -8
View File
@@ -1,21 +1,19 @@
import { Db } from "mongodb";
import { Omit } from "talk-common/types";
import {
CommentStatus,
createComment,
CreateCommentInput,
} from "talk-server/models/comment";
import { GQLCOMMENT_STATUS } from "talk-server/graph/tenant/schema/__generated__/types";
import { createComment, CreateCommentInput } from "talk-server/models/comment";
import { Tenant } from "talk-server/models/tenant";
export type CreateComment = Omit<
CreateCommentInput,
"status" | "action_counts"
>;
export async function create(db: Db, tenantID: string, input: CreateComment) {
export async function create(db: Db, tenant: Tenant, input: CreateComment) {
// TODO: run the comment through the moderation phases.
const comment = await createComment(db, tenantID, {
status: CommentStatus.ACCEPTED,
const comment = await createComment(db, tenant.id, {
status: GQLCOMMENT_STATUS.ACCEPTED,
action_counts: {},
...input,
});