Skip to content

Commit

Permalink
feat: Add support for io.cozy.bills
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed May 30, 2024
1 parent 97e233f commit ef2d9ce
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 5 additions & 0 deletions manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
"type": "io.cozy.files",
"verbs": ["ALL"]
},
"bills": {
"description": "Required to access the bills",
"type": "io.cozy.bills",
"verbs": ["ALL"]
},
"sharings": {
"description": "Required to have access to the sharings in realtime",
"type": "io.cozy.sharings",
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const FILES_DOCTYPE = 'io.cozy.files'
export const TRIGGERS_DOCTYPE = 'io.cozy.triggers'
export const APP_SETTINGS_DOCTYPE = 'io.cozy.mespapiers.settings'
export const JOBS_DOCTYPE = 'io.cozy.jobs'
export const BILLS_DOCTYPE = 'io.cozy.bills'

export const APP_SLUG = 'mespapiers'
export const EXPIRATION_SERVICE_NAME = 'expiration'
Expand Down
43 changes: 41 additions & 2 deletions src/doctypes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
import { CONTACTS_DOCTYPE, FILES_DOCTYPE } from 'src/constants'
import { CONTACTS_DOCTYPE, FILES_DOCTYPE, BILLS_DOCTYPE } from 'src/constants'

import { QueryDefinition, HasMany } from 'cozy-client'

class HasManyBills extends HasMany {
get data() {
const refs = this.target.relationships.referenced_by.data
return refs
? refs
.map(ref => {
if (ref.type === BILLS_DOCTYPE) {
return this.get(ref.type, ref.id)
}
})
.filter(Boolean)
: []
}

static query(doc, client, assoc) {
if (
!doc.relationships ||
!doc.relationships.referenced_by ||
!doc.relationships.referenced_by.data
) {
return null
}

const included = doc.relationships.referenced_by.data
const ids = included
.filter(inc => inc.type === assoc.doctype)
.map(inc => inc.id)

return new QueryDefinition({ doctype: assoc.doctype, ids })
}
}

// the documents schema, necessary for CozyClient
export default {
Expand All @@ -10,6 +44,11 @@ export default {
files: {
doctype: FILES_DOCTYPE,
attributes: {},
relationships: {}
relationships: {
bills: {
type: HasManyBills,
doctype: BILLS_DOCTYPE
}
}
}
}

0 comments on commit ef2d9ce

Please sign in to comment.