twenty-server 0.4.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6d4515968ee8d57313cdb7c60c3d166945b33d702773de96a0e04401b9e6b88
4
- data.tar.gz: 56be6f5feadf5555c91b96eb0ad8513824ba3ecf07ef77da75359153d26a4d3a
3
+ metadata.gz: b83eb9e96d4001197f2e9b1433fafcb65b596be12ee1ee524e65a052f1414ee6
4
+ data.tar.gz: 888fa18f5343736fc57aaf55b9be0cc35939420296a7bc42b24bc5d7a06bf2a9
5
5
  SHA512:
6
- metadata.gz: 80385987dcce1b2c0a49705b84cefc1057daba9df9128b89c29c8f0799101748b2d4dde3c430af4b17796227207e8f357f580771372bae06ca2388b3ac0de227
7
- data.tar.gz: cded3a241a6e8df4512625ffa08cc6e5ea7dcae1b4c5674706a30f659fa7a3972d56e2aa5047dee02987cdab921e52785109f8d833b8ac0ee0ab0ec50d37bef5
6
+ metadata.gz: ba09669cff1d0342c78a4b1f972a6d61028b31103fddfa1330f3d859dd533e51a46198c5636f4a28ceb4202889d891d251fa432c6c626b1a21a569c6a723ce57
7
+ data.tar.gz: 0a05f5c006ce39024ab619133bb26de572c3aa97faf7430979336c0c8a051557d2d88120fbc3c79a95840ff4a6b9447bb56118d739d62b671af45b2cdb7724df
@@ -7,5 +7,6 @@ module Twenty::GraphQL::Type
7
7
  field :path, String, null: false
8
8
  field :color, String, null: false
9
9
  field :tasks, "[Twenty::GraphQL::Type::Task]", null: false
10
+ field :open_task_count, Integer, null: false
10
11
  end
11
12
  end
@@ -23,7 +23,10 @@ module Twenty::GraphQL::Type
23
23
  end
24
24
 
25
25
  def projects
26
- Twenty::Project.all
26
+ Twenty::Project
27
+ .all
28
+ .sort_by { _1.open_task_count }
29
+ .reverse
27
30
  end
28
31
  end
29
32
  end
@@ -8,10 +8,35 @@ class Twenty::Project < Sequel::Model
8
8
  validates_presence_of :path
9
9
  one_to_many :tasks, class_name: "Twenty::Task"
10
10
 
11
+ ##
12
+ # @api private
13
+ def validate
14
+ super
15
+ errors.add(:path, "does not exist on disk") if !path_exist?
16
+ errors.add(:path, "is not absolute") if !File.absolute_path?(path)
17
+ end
18
+
11
19
  ##
12
20
  # @return [String]
13
- # The path to a project.
21
+ # The path to a project
14
22
  def path
15
23
  super&.sub(Dir.home, "~")
16
24
  end
25
+
26
+ ##
27
+ # @return [Boolean]
28
+ # Returns true when {#path} exists on disk
29
+ def path_exist?
30
+ File.exist? File.expand_path(path)
31
+ end
32
+
33
+ ##
34
+ # @return [Integer]
35
+ # Returns the number of open tasks a project has
36
+ def open_task_count
37
+ @open_task_count ||= Twenty::Task
38
+ .where(project_id: id)
39
+ .where(Sequel.lit("status IN (0,1,2)"))
40
+ .count
41
+ end
17
42
  end
@@ -4,13 +4,13 @@ module Twenty::Rack
4
4
  module GraphQL
5
5
  ##
6
6
  # Extends {Server::Dir Server::Dir} (a static file
7
- # Rack application) with a /graphql endpoint.
7
+ # Rack application) with a /graphql endpoint
8
8
  #
9
9
  # @param [Hash] env
10
- # Environment hash.
10
+ # Environment hash
11
11
  #
12
12
  # @return [Array<Integer, Hash, #each>]
13
- # Returns a response.
13
+ # Returns a response
14
14
  def call(env)
15
15
  req = Rack::Request.new(env)
16
16
  if req.post? &&
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twenty
4
+ require "fileutils"
5
+ require "sequel"
6
+ require_relative "server/path"
7
+
8
+ ##
9
+ # @return [String]
10
+ # Returns the location of the default SQLite database.
11
+ def self.default_database
12
+ @default_database ||= File.join(Path.datadir, "database.sqlite")
13
+ end
14
+
15
+ ##
16
+ # Establishes a database connection.
17
+ #
18
+ # @param [String] path
19
+ # The path to a SQLite3 database file.
20
+ #
21
+ # @return [void]
22
+ def self.establish_connection(path:)
23
+ @connection = Sequel.connect(
24
+ adapter: "sqlite",
25
+ database: path
26
+ )
27
+ end
28
+
29
+ def self.connection
30
+ establish_connection unless @connection
31
+ @connection
32
+ end
33
+
34
+ FileUtils.touch(default_database)
35
+ require_relative "server/graphql"
36
+ require_relative "server/rack"
37
+ end
@@ -38,6 +38,7 @@ type Project {
38
38
  color: String!
39
39
  id: Int!
40
40
  name: String!
41
+ openTaskCount: Int!
41
42
  path: String!
42
43
  tasks: [Task!]!
43
44
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twenty-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-25 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -101,6 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - "./lib/twenty/server.rb"
104
105
  - "./lib/twenty/server/graphql.rb"
105
106
  - "./lib/twenty/server/graphql/input.rb"
106
107
  - "./lib/twenty/server/graphql/input/task_input.rb"