forked from andyburke/autonomous.contact
refactor: first pass on getting the client back into working order
(still broken, but loading as a baseline)
This commit is contained in:
parent
a5707e2f81
commit
afeb6f75e8
23 changed files with 358 additions and 322 deletions
|
|
@ -4,7 +4,7 @@ import * as CANNED_RESPONSES from '../../../../../utils/canned_responses.ts';
|
|||
import { get_session, get_user, PRECHECK_TABLE, require_user } from '../../../../../utils/prechecks.ts';
|
||||
import parse_body from '../../../../../utils/bodyparser.ts';
|
||||
import lurid from '@andyburke/lurid';
|
||||
import { TOPICS } from '../../../../../models/topic.ts';
|
||||
import { CHANNELS } from '../../../../../models/channel.ts';
|
||||
|
||||
export const PRECHECKS: PRECHECK_TABLE = {};
|
||||
|
||||
|
|
@ -99,34 +99,18 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
|
|||
}
|
||||
};
|
||||
|
||||
const topic = await TOPICS.get(watch.topic_id);
|
||||
if (!topic) {
|
||||
return Response.json({
|
||||
errors: [{
|
||||
cause: 'invalid_topic_id',
|
||||
message: 'Could not find a topic with id: ' + watch.topic_id
|
||||
}]
|
||||
}, {
|
||||
status: 400
|
||||
});
|
||||
}
|
||||
|
||||
const existing_watch: WATCH | undefined = (await WATCHES.find({
|
||||
creator_id: meta.user.id,
|
||||
topic_id: topic.id
|
||||
}, {
|
||||
limit: 1
|
||||
})).shift()?.load();
|
||||
|
||||
if (existing_watch) {
|
||||
return Response.json({
|
||||
errors: [{
|
||||
cause: 'existing_watch',
|
||||
message: 'You already have a watch for this topic.'
|
||||
}]
|
||||
}, {
|
||||
status: 400
|
||||
});
|
||||
if (watch.channel) {
|
||||
const channel = await CHANNELS.get(watch.channel);
|
||||
if (!channel) {
|
||||
return Response.json({
|
||||
errors: [{
|
||||
cause: 'invalid_channel_id',
|
||||
message: 'Could not find a channel with id: ' + watch.channel
|
||||
}]
|
||||
}, {
|
||||
status: 400
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await WATCHES.create(watch);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue