@@ -95,6 +95,30 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
9595 end
9696 end
9797
98+ @ doc """
99+ notify(email) admin about new content
100+ NOTE: this method should NOT be pravite, because this method
101+ will be called outside this module
102+ """
103+ def notify_admin_new_content ( % { id: id } = result ) do
104+ target = result . __struct__
105+ preload = [ :origial_community , author: :user ]
106+
107+ with { :ok , content } <- ORM . find ( target , id , preload: preload ) do
108+ info = % {
109+ id: content . id ,
110+ title: content . title ,
111+ digest: Map . get ( content , :digest , content . title ) ,
112+ author_name: content . author . user . nickname ,
113+ community_raw: content . origial_community . raw ,
114+ type:
115+ result . __struct__ |> to_string |> String . split ( "." ) |> List . last ( ) |> String . downcase ( )
116+ }
117+
118+ Email . notify_admin ( info , :new_content )
119+ end
120+ end
121+
98122 @ doc """
99123 update a content(post/job ...)
100124 """
@@ -478,23 +502,4 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
478502 |> Repo . update ( )
479503 end
480504 end
481-
482- defp notify_admin_new_content ( % { id: id } = result ) do
483- target = result . __struct__
484- preload = [ :origial_community , author: :user ]
485-
486- with { :ok , content } <- ORM . find ( target , id , preload: preload ) do
487- info = % {
488- id: content . id ,
489- title: content . title ,
490- digest: Map . get ( content , :digest , content . title ) ,
491- author_name: content . author . user . nickname ,
492- community_raw: content . origial_community . raw ,
493- type:
494- result . __struct__ |> to_string |> String . split ( "." ) |> List . last ( ) |> String . downcase ( )
495- }
496-
497- Email . notify_admin ( info , :new_content )
498- end
499- end
500505end
0 commit comments