1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-14 02:06:29 +00:00

article CRUD with socket

This commit is contained in:
Rokt33r
2015-10-16 22:12:49 +09:00
parent a1810e6023
commit 2a339a2935
12 changed files with 176 additions and 99 deletions

View File

@@ -1,107 +1,111 @@
var request = require('superagent-promise')(require('superagent'), Promise)
var apiUrl = require('../config').apiUrl
import superagent from 'superagent'
import superagentPromise from 'superagent-promise'
import { API_URL } from '../config'
import auth from 'boost/auth'
const request = superagentPromise(superagent, Promise)
export function login (input) {
return request
.post(apiUrl + 'auth/login')
.post(API_URL + 'auth/login')
.send(input)
}
export function signup (input) {
return request
.post(apiUrl + 'auth/register')
.post(API_URL + 'auth/register')
.send(input)
}
export function fetchCurrentUser () {
return request
.get(apiUrl + 'auth/user')
.get(API_URL + 'auth/user')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
}
export function fetchArticles (userId) {
return request
.get(apiUrl + 'teams/' + userId + '/articles')
.get(API_URL + 'teams/' + userId + '/articles')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
}
export function createArticle (input) {
return request
.post(apiUrl + 'articles/')
.post(API_URL + 'articles/')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function saveArticle (input) {
return request
.put(apiUrl + 'articles/' + input.id)
.put(API_URL + 'articles/' + input.id)
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function destroyArticle (articleId) {
return request
.del(apiUrl + 'articles/' + articleId)
.del(API_URL + 'articles/' + articleId)
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
}
export function createTeam (input) {
return request
.post(apiUrl + 'teams')
.post(API_URL + 'teams')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function searchUser (key) {
return request
.get(apiUrl + 'search/users')
.get(API_URL + 'search/users')
.query({key: key})
}
export function setMember (teamId, input) {
return request
.post(apiUrl + 'teams/' + teamId + '/members')
.post(API_URL + 'teams/' + teamId + '/members')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function deleteMember (teamId, input) {
return request
.del(apiUrl + 'teams/' + teamId + '/members')
.del(API_URL + 'teams/' + teamId + '/members')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function createFolder (input) {
return request
.post(apiUrl + 'folders/')
.post(API_URL + 'folders/')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}
export function sendEmail (input) {
return request
.post(apiUrl + 'mail')
.post(API_URL + 'mail')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
Authorization: 'Bearer ' + auth.token()
})
.send(input)
}