11/**
22 * Sort a multi-select's options alphabetically.
33 *
4+ * Note: you can only sort up to 100 options like this!
5+ *
46 * Arguments:
57 *
6- * --database -id: ID of the database to create in
8+ * --data-source -id: ID of the database to create in
79 * --sort-prop: name of multi-select to sort
810 * --[no-]case-sensitive: whether to sort ABCabc (default or --case-sensitive) or AaBbCc (--no-case-sensitive)
911 */
@@ -12,30 +14,30 @@ const { notion, yargs } = require('../../shared');
1214const { log } = require ( '../../shared/utils' ) ;
1315const _ = require ( 'lodash' ) ;
1416
15- const databaseId = 'f91e66f29d63457894be7c91b132f345 ' ;
17+ const dataSourceId = '1cf71d94-0107-4560-a702-a41cb5d90aea ' ;
1618const sortProp = 'Feeling' ;
1719const argv = yargs
1820 . boolean ( 'case-sensitive' )
19- . default ( { databaseId , sortProp, caseSensitive : true } ) . argv ;
21+ . default ( { dataSourceId , sortProp, caseSensitive : true } ) . argv ;
2022
2123( async ( ) => {
22- let database = await notion . databases . retrieve ( {
23- database_id : argv . databaseId ,
24+ let dataSource = await notion . dataSources . retrieve ( {
25+ data_source_id : argv . dataSourceId ,
2426 } ) ;
2527
26- const propId = database . properties [ argv . sortProp ] . id ;
28+ const propId = dataSource . properties [ argv . sortProp ] . id ;
2729 const iteratee = argv . caseSensitive ? 'name' : [ ( option ) => option . name . toLowerCase ( ) ] ;
2830
2931 // Sort the options and remove color since it cannot be updated via API
3032 const sortedOptions = _ . map (
31- _ . orderBy ( database . properties [ argv . sortProp ] . multi_select . options , iteratee ) ,
33+ _ . orderBy ( dataSource . properties [ argv . sortProp ] . multi_select . options , iteratee ) ,
3234 ( option ) => {
3335 return _ . omit ( option , 'color' ) ;
3436 }
3537 ) ;
3638
3739 const properties = {
38- database_id : argv . databaseId ,
40+ data_source_id : argv . dataSourceId ,
3941 properties : {
4042 [ propId ] : {
4143 multi_select : {
@@ -45,8 +47,7 @@ const argv = yargs
4547 } ,
4648 } ;
4749
48- // FIXME: use data sources
49- database = await notion . databases . update ( properties ) ;
50+ dataSource = await notion . dataSources . update ( properties ) ;
5051
51- log ( database . properties [ argv . sortProp ] ) ;
52+ log ( dataSource . properties [ argv . sortProp ] ) ;
5253} ) ( ) ;
0 commit comments