pub fn generate_access_token(&self, user_id: ID) -> Result<AccessToken> {
        use crate::schema::access_tokens::{self, dsl};

        let now = chrono::Utc::now().naive_utc();

        // hapus token lama kalau ada
        // diesel::delete(dsl::access_tokens.filter(dsl::user_id.eq(user_id))).execute(self.db)?;

        let token = NewAccessToken {
            token: &token::generate_access_token(),
            user_id,
            created: now,
            valid_thru: now
                .checked_add_signed(Duration::days(7))
                .expect("cannot assign valid_thru time"),
        };

        diesel::insert_into(access_tokens::table)
            .values(&token)
            .get_result(self.db)
            .map_err(From::from)
    }
/// Generate access token, this write access token into database.
Generate access token, this write access token into database.
Generate access token this write access token into database .
pub fn generate_access_token(&self, user_id: ID) -> Result<AccessToken> {
        use crate::schema::access_tokens::{self, dsl};
        let now = chrono::Utc::now().naive_utc();
        // hapus token lama kalau ada
        // diesel::delete(dsl::access_tokens.filter(dsl::user_id.eq(user_id))).execute(self.db)?;
        let token = NewAccessToken {
            token: &token::generate_access_token(),
            user_id,
            created: now,
            valid_thru: now
                .checked_add_signed(Duration::days(7))
                .expect("cannot assign valid_thru time"),
        };
        diesel::insert_into(access_tokens::table)
            .values(&token)
            .get_result(self.db)
            .map_err(From::from)
    }
pub fn generate_access_token ( & self , user_id : ID ) -> Result < AccessToken > { use crate :: schema :: access_tokens :: { self , dsl } ; let now = chrono :: Utc :: now ( ) . naive_utc ( ) ; // hapus token lama kalau ada // diesel::delete(dsl::access_tokens.filter(dsl::user_id.eq(user_id))).execute(self.db)?; let token = NewAccessToken { token : & token :: generate_access_token ( ) , user_id , created : now , valid_thru : now . checked_add_signed ( Duration :: days ( 7 ) ) . expect ( " " ) , } ; diesel :: insert_into ( access_tokens :: table ) . values ( & token ) . get_result ( self . db ) . map_err ( From :: from ) }
Generate access token, this write access token into database.
Generate access token this write access token into database .
&self
user_id
ID
&self
user_id
ID