mgebbe@0: # Copyright (C) 2014 by Intevation GmbH mgebbe@0: # Author: Mathias Gebbe mgebbe@0: # mgebbe@3: # This file is Free Software under the Apache License, Version 2.0; mgebbe@3: # and comes with NO WARRANTY! mgebbe@3: # See the documentation coming with pumpbridge for details. mgebbe@0: mgebbe@0: _ = require("underscore") mgebbe@0: async = require("async") mgebbe@0: DatabankObject = require("databank").DatabankObject mgebbe@0: FromESN = DatabankObject.subClass("fromESN") mgebbe@0: mgebbe@0: FromESN.schema = mgebbe@0: pkey: "uid" mgebbe@0: fields: [ mgebbe@0: "postid" mgebbe@0: "sourceUser" mgebbe@0: "sourcePost" mgebbe@0: "pumpPost" mgebbe@0: "recipientUser" mgebbe@0: "created" mgebbe@0: "updated" mgebbe@0: ] mgebbe@0: indices: [ mgebbe@0: "postid" mgebbe@0: "sourceUser" mgebbe@0: "sourcePost" mgebbe@0: "pumpPost" mgebbe@0: "recipientUser" mgebbe@0: ] mgebbe@0: mgebbe@0: FromESN.beforeCreate = (props, callback) -> mgebbe@0: if not props.sourcePost or not props.sourceUser mgebbe@0: callback new Error("Need 'sourceUser' and 'sourceUser'"), null mgebbe@0: return mgebbe@0: props.uid = FromESN.key(props.postid , props.recipientUser) mgebbe@0: props.created = Date.now() mgebbe@0: props.updated = Date.now() mgebbe@0: callback null, props mgebbe@0: return mgebbe@0: mgebbe@0: FromESN::beforeSave = (callback) -> mgebbe@0: props = this mgebbe@0: if not props.sourcePost or not props.sourceUser mgebbe@0: callback new Error("Need 'sourceUser' and 'sourceUser'"), null mgebbe@0: return mgebbe@0: props.updated = Date.now() mgebbe@0: callback null mgebbe@0: return mgebbe@0: mgebbe@0: FromESN.key = (postid, recipientUser) -> mgebbe@0: postid + "_to_" + recipientUser mgebbe@0: mgebbe@0: module.exports = FromESN