addListLogic.js 1.64 KB
import {observable} from 'mobx'
import {_createList, _getListUser, _editList, _getTaskList} from "../service/AppService";
import {ownerUserId,ownerUserName} from "../service/rpc";
import Toast from "react-native-simple-toast";
export default class addListLogic {
	@observable
	text = ""
	@observable
	userList = []
	rowVersion = ""
	ownerUserId=""
	async create() {
		console.log(JSON.stringify(this.userList.map(v=>({userId:v.userId,userName:v.name}))),)
		try{
			const result = await _createList({
				ownerUserId,
				objectName: this.text,
				objectType: "MANUAL",
				userList: JSON.stringify(this.userList),
			})
			const {errors,firstErrorMessage,id}=result
			if(errors.length>0){
				Toast.show(firstErrorMessage)
				return
			}
			return id
		}catch(e){
			console.warn(e)
		}

	}

	async edit(params) {
		const userList=JSON.stringify(this.userList.map(v=>{return {userId:v.userId,userName:v.userName,}}))
		console.log(userList)
		try{
			const data =await  _editList({
				objectName: this.text,
				...params,
				userList: userList,
				rowVersion: this.rowVersion,
				ownerUserId:this.ownerUserId,
			})
			const {errors,firstErrorMessage,}=data
			if(errors.length>0){
				Toast.show(firstErrorMessage)
			}
		}catch(e){
			console.warn(e)
		}


	}

	async getTaskList(id) {
		try{
			const data = await _getTaskList({id})
			const {taskList, userList,errors,firstErrorMessage,} = data
			if(errors.length>0){
				Toast.show(firstErrorMessage)
			}else{
				const {rowVersion, objectName} = taskList
				this.rowVersion = rowVersion
				this.text = objectName
				this.userList.replace(userList)
				this.ownerUserId=ownerUserId
			}
		}catch(e){

		}

	}
}