Merge branch 'next' into next-respect

This commit is contained in:
Wyatt Johnson
2018-09-18 15:56:38 -06:00
committed by GitHub
208 changed files with 5834 additions and 1187 deletions
+12 -9
View File
@@ -136,12 +136,7 @@ async function addCommentActions(
export type EditComment = Omit<
EditCommentInput,
"status" | "author_id" | "lastEditableCommentCreatedAt"
> & {
/**
* asset_id is the asset that the comment exists on.
*/
asset_id: string;
};
>;
export async function edit(
mongo: Db,
@@ -150,15 +145,22 @@ export async function edit(
input: EditComment,
req?: Request
) {
// Get the comment that we're editing.
let comment = await retrieveComment(mongo, tenant.id, input.id);
if (!comment) {
// TODO: replace to match error returned by the models/comments.ts
throw new Error("comment not found");
}
// Grab the asset that we'll use to check moderation pieces with.
const asset = await retrieveAsset(mongo, tenant.id, input.asset_id);
const asset = await retrieveAsset(mongo, tenant.id, comment.asset_id);
if (!asset) {
// TODO: (wyattjoh) return better error.
throw new Error("asset referenced does not exist");
}
// Run the comment through the moderation phases.
const { status } = await processForModeration({
const { status, metadata } = await processForModeration({
asset,
tenant,
comment: input,
@@ -168,11 +170,12 @@ export async function edit(
// TODO: (wyattjoh) use the actions somehow.
const comment = await editComment(mongo, tenant.id, {
comment = await editComment(mongo, tenant.id, {
id: input.id,
author_id: author.id,
body: input.body,
status,
metadata,
// The editable time is based on the current time, and the edit window
// length. By subtracting the current date from the edit window length, we
// get the maximum value for the `created_at` time that would be permitted