From e2ad5920079d782ef9dd4cd947ecf71eb0056658 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 15 Mar 2018 10:53:17 +0630 Subject: [PATCH] update start import and export menu --- data/recent_users.json | 128 +++++++++++++++++++++++++++++++++++++++++ lib/tasks/receipt.rake | 40 +++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 data/recent_users.json diff --git a/data/recent_users.json b/data/recent_users.json new file mode 100644 index 00000000..4d2e6825 --- /dev/null +++ b/data/recent_users.json @@ -0,0 +1,128 @@ +[ + { + "id": 1, + "name": "Administrator", + "role": "administrator", + "emp_id": "999", + "password_digest": "$2a$10$mfWmxBvOHt3NbWrLGOF/POTpnxF7QEtnW99qW818dkrQqVLtjQdrS", + "token_session": null, + "session_expiry": null, + "session_last_login": "2018-03-14 09:41:25 +0630", + "created_by": "SYSTEM DEFAULT", + "created_at": "2017-11-08 09:44:30 +0630", + "updated_at": "2018-03-14 16:02:09 +0630", + "image_path": {"url":null} + }, + { + "id": 2, + "name": "Waiter", + "role": "waiter", + "emp_id": "111", + "password_digest": "$2a$10$PjBemEA2yKOcoGAyXjz81OqglrASIF8RTYHVe0vqp3FQ0T4/PzJJG", + "token_session": "662e797ad508ab6c43b1", + "session_expiry": "2018-02-21 01:45:11 +0630", + "session_last_login": "2018-02-20 13:45:11 +0630", + "created_by": "SYSTEM DEFAULT", + "created_at": "2017-11-08 09:44:30 +0630", + "updated_at": "2018-02-20 13:59:17 +0630", + "image_path": {"url":null} + }, + { + "id": 3, + "name": "Waiter 2", + "role": "waiter", + "emp_id": "222", + "password_digest": "$2a$10$gXh/Tpbr8EyJSaxsbJYVh.K7Fr4bT0A1i2mWuuZm/FHQ4D/wV1E8e", + "token_session": "61868be9530b753ada84", + "session_expiry": "2018-03-14 05:41:12 +0630", + "session_last_login": "2018-03-13 17:11:12 +0630", + "created_by": "SYSTEM DEFAULT", + "created_at": "2017-11-08 09:44:30 +0630", + "updated_at": "2018-03-13 17:32:47 +0630", + "image_path": {"url":null} + }, + { + "id": 4, + "name": "Cashier", + "role": "cashier", + "emp_id": "333", + "password_digest": "$2a$10$fHo.9wOn.yr.2Ke6iuCfou6DjpyHXwQSmZQ.43O7W4SnlmzuoIEF2", + "token_session": "693f6e98bb90b6af9978", + "session_expiry": "2018-03-15 12:36:28 +0630", + "session_last_login": "2018-03-14 16:36:28 +0630", + "created_by": "SYSTEM DEFAULT", + "created_at": "2017-11-08 09:44:30 +0630", + "updated_at": "2018-03-14 17:05:14 +0630", + "image_path": {"url":null} + }, + { + "id": 5, + "name": "manager", + "role": "manager", + "emp_id": "888", + "password_digest": "$2a$10$EaU/Sxfsb8Q3kBIAyxSEJ.ZpRC9vxSdVAFvF0WXUvWiAqHyqGggoe", + "token_session": null, + "session_expiry": null, + "session_last_login": "2018-01-16 13:37:05 +0630", + "created_by": null, + "created_at": "2017-11-30 10:03:11 +0630", + "updated_at": "2018-01-16 13:48:02 +0630", + "image_path": {"url":null} + }, + { + "id": 6, + "name": "Account", + "role": "account", + "emp_id": "777", + "password_digest": "$2a$10$bJmgIxHefkvxpxJQLQPcpurTJrp8.BwP/kirJRYb1v1thrU3TDzkC", + "token_session": null, + "session_expiry": null, + "session_last_login": "2018-01-16 10:37:22 +0630", + "created_by": null, + "created_at": "2018-01-16 10:23:09 +0630", + "updated_at": "2018-01-16 10:49:24 +0630", + "image_path": {"url":null} + }, + { + "id": 7, + "name": "Supervisor", + "role": "supervisor", + "emp_id": "666", + "password_digest": "$2a$10$/WQirOw5nu6kKDiITTVa7.IGeVyxH5JmLp3/Astu/5DlOAoMLn4Ne", + "token_session": null, + "session_expiry": null, + "session_last_login": "2018-01-16 14:28:40 +0630", + "created_by": null, + "created_at": "2018-01-16 10:23:32 +0630", + "updated_at": "2018-01-16 15:32:33 +0630", + "image_path": {"url":null} + }, + { + "id": 8, + "name": "123", + "role": "waiter", + "emp_id": "123", + "password_digest": "$2a$10$v8JBsc31XkLRNZ/QhfYBg.wbVT7CyVvk83U..0PsGiz61w0Atl/WW", + "token_session": "4fc9a18a5df511e507fc", + "session_expiry": "2018-02-01 20:08:35 +0630", + "session_last_login": "2018-02-01 14:08:35 +0630", + "created_by": null, + "created_at": "2018-02-01 14:07:16 +0630", + "updated_at": "2018-02-01 17:45:10 +0630", + "image_path": {"url":null} + }, + { + "id": 9, + "name": "Cashier 2", + "role": "cashier", + "emp_id": "444", + "password_digest": "$2a$10$5n34O09xmrIHbgvX.uhr9uAaUR8etjaqiicaXr017VWm/qDkjKVue", + "token_session": "0477edce9cf259f280c1", + "session_expiry": "2018-02-20 19:07:50 +0630", + "session_last_login": "2018-02-20 11:37:50 +0630", + "created_by": null, + "created_at": "2018-02-14 17:10:12 +0630", + "updated_at": "2018-02-20 13:37:46 +0630", + "image_path": {"url":null} + } +] \ No newline at end of file diff --git a/lib/tasks/receipt.rake b/lib/tasks/receipt.rake index fa24f481..ee884fb2 100644 --- a/lib/tasks/receipt.rake +++ b/lib/tasks/receipt.rake @@ -1,4 +1,44 @@ namespace :consolidate do + + + desc 'export sers who have logged in since 2017-06-30' + task :export => :environment do + puts "Export users who have logged in since 2017-06-30" + + # get a file ready, the 'data' directory has already been added in Rails.root + filepath = File.join(Rails.root, 'data', 'recent_users.json') + puts "- exporting users into #{filepath}" + + # the key here is to use 'as_json', otherwise you get an ActiveRecord_Relation object, which extends + # array, and works like in an array, but not for exporting + users = Employee.all.as_json +puts users + # The pretty is nice so I can diff exports easily, if that's not important, JSON(users) will do + File.open(filepath, 'w') do |f| + f.write(JSON.pretty_generate(users)) + end + + puts "- dumped #{users.size} users" + end + + desc 'import users from recent users dump' + task :import => :environment do + puts "Importing current users" + + filepath = File.join(Rails.root, 'data', 'recent_users.json') + abort "Input file not found: #{filepath}" unless File.exist?(filepath) + + current_users = JSON.parse(File.read(filepath)) + + current_users.each do |cu| + puts cu.to_json + Employee.create(cu) + end + + puts "- imported #{current_users.size} users" + end + + desc "Receipt" task :receipt => :environment do Receipt.delete_all