You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
const { handleArrayDaoData } = require ( "../utils/tools" ) ;
const addressModel = require ( "./model/addressModel" ) ;
module . exports . getAddressDao = async function ( senderId ) {
// 如果有senderId参数, 则添加查询条件
const whereCondition = senderId ? { senderId } : { } ;
return handleArrayDaoData (
await addressModel . findAll ( {
where : whereCondition ,
} )
) ;
} ;
module . exports . addAddressDao = async function ( addressData ) {
// 如果新增的是默认地址,需要先将其他地址设为非默认
if ( addressData . isDefault === 1 ) {
await addressModel . update ( { isDefault : 0 } , { where : { } } ) ;
}
await addressModel . create ( addressData ) ;
return handleArrayDaoData ( await addressModel . findAll ( ) ) ;
} ;
module . exports . updateAddressDao = async function ( addressData ) {
// 如果更新的是默认地址,需要先将其他地址设为非默认
if ( addressData . isDefault === 1 ) {
await addressModel . update (
{ isDefault : 0 } ,
{
where : { id : { [ Op . ne ] : addressData . id } } ,
}
) ;
}
await addressModel . update ( addressData , {
where : {
id : addressData . id ,
} ,
} ) ;
return handleArrayDaoData ( await addressModel . findAll ( ) ) ;
} ;
module . exports . deleteAddressDao = async function ( id ) {
await addressModel . destroy ( {
where : {
id ,
} ,
} ) ;
return handleArrayDaoData ( await addressModel . findAll ( ) ) ;
} ;