mgebbe@0: # Copyright (C) 2014 by Intevation GmbH mgebbe@0: # Author: Mathias Gebbe mgebbe@0: # mgebbe@0: # This file is Free Software under the Apache License, Version 2.0 mgebbe@0: # (the "License"); and comes with ABSOLUTELY NO WARRANTY! mgebbe@0: # You may not use this file except in compliance with the License. mgebbe@0: # See LICENSE for details. mgebbe@0: mgebbe@0: _ = require("underscore") mgebbe@0: async = require("async") mgebbe@0: DatabankObject = require("databank").DatabankObject mgebbe@0: CommentToESN = DatabankObject.subClass("CommentToESN") mgebbe@0: mgebbe@0: CommentToESN.schema = mgebbe@0: pkey: "uid" mgebbe@0: fields: [ mgebbe@0: "ESNPost" mgebbe@0: "pumpComment" mgebbe@0: "created" mgebbe@0: "updated" mgebbe@0: ] mgebbe@0: indices: [ mgebbe@0: "ESNPost" mgebbe@0: "pumpComment" mgebbe@0: ] mgebbe@0: mgebbe@0: CommentToESN.beforeCreate = (props, callback) -> mgebbe@0: if not props.ESNPost or not props.pumpComment mgebbe@0: callback new Error("Need 'ESNPost' and 'pumpComment'"), null mgebbe@0: return mgebbe@0: props.uid = CommentToESN.key(props.pumpComment, props.ESNPost) mgebbe@0: props.created = Date.now() mgebbe@0: props.updated = Date.now() mgebbe@0: callback null, props mgebbe@0: return mgebbe@0: mgebbe@0: CommentToESN::beforeSave = (callback) -> mgebbe@0: props = this mgebbe@0: if not props.ESNPost or not props.pumpComment mgebbe@0: callback new Error("Need 'ESNPost' and 'pumpComment'"), null mgebbe@0: return mgebbe@0: props.updated = Date.now() mgebbe@0: callback null mgebbe@0: return mgebbe@0: mgebbe@0: CommentToESN.key = (pumpComment, ESNPost) -> mgebbe@0: pumpComment + "_to_" + ESNPost mgebbe@0: mgebbe@0: module.exports = CommentToESN