Mercurial > pumpbridge
comparison src/fromESN.coffee @ 0:b73191efc65b
Initial import of pumpbridge (bloody bloody alpha)
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Thu, 05 Jun 2014 10:35:15 +0200 |
parents | |
children | 98a070c98982 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b73191efc65b |
---|---|
1 # Copyright (C) 2014 by Intevation GmbH | |
2 # Author: Mathias Gebbe <mgebbe@intevation.de> | |
3 # | |
4 # This file is Free Software under the Apache License, Version 2.0 | |
5 # (the "License"); and comes with ABSOLUTELY NO WARRANTY! | |
6 # You may not use this file except in compliance with the License. | |
7 # See LICENSE for details. | |
8 | |
9 _ = require("underscore") | |
10 async = require("async") | |
11 DatabankObject = require("databank").DatabankObject | |
12 FromESN = DatabankObject.subClass("fromESN") | |
13 | |
14 FromESN.schema = | |
15 pkey: "uid" | |
16 fields: [ | |
17 "postid" | |
18 "sourceUser" | |
19 "sourcePost" | |
20 "pumpPost" | |
21 "recipientUser" | |
22 "created" | |
23 "updated" | |
24 ] | |
25 indices: [ | |
26 "postid" | |
27 "sourceUser" | |
28 "sourcePost" | |
29 "pumpPost" | |
30 "recipientUser" | |
31 ] | |
32 | |
33 FromESN.beforeCreate = (props, callback) -> | |
34 if not props.sourcePost or not props.sourceUser | |
35 callback new Error("Need 'sourceUser' and 'sourceUser'"), null | |
36 return | |
37 props.uid = FromESN.key(props.postid , props.recipientUser) | |
38 props.created = Date.now() | |
39 props.updated = Date.now() | |
40 callback null, props | |
41 return | |
42 | |
43 FromESN::beforeSave = (callback) -> | |
44 props = this | |
45 if not props.sourcePost or not props.sourceUser | |
46 callback new Error("Need 'sourceUser' and 'sourceUser'"), null | |
47 return | |
48 props.updated = Date.now() | |
49 callback null | |
50 return | |
51 | |
52 FromESN.key = (postid, recipientUser) -> | |
53 postid + "_to_" + recipientUser | |
54 | |
55 module.exports = FromESN |